Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Gregory Ewing Newsgroups: comp.lang.python Subject: Re: Function declarations ? Date: Tue, 14 Jun 2011 14:03:30 +1200 Lines: 32 Message-ID: <95ntriFod7U1@mid.individual.net> References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net CaC/JM0fOo3b/G45VzhovgfgLj9L6NEabCs4kjHOM3hVOgXgj+ Cancel-Lock: sha1:2TIrZMZ1r8S2ypBTh+Ora9S0JbA= User-Agent: Mozilla Thunderbird 1.0.5 (Macintosh/20050711) X-Accept-Language: en-us, en In-Reply-To: Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:7580 Tim Roberts wrote: > Andre Majorel wrote: > >>Anyway, it seems the Python way to declare a function is >> >> def f (): >> pass > > No, that DEFINES a function. Actually, it's more illuminating to say that it *creates* a function. The 'def' statement in Python is an executable statement. Executing it has the effect of creating a function object and binding it to the indicated name. Before that has happened, attempting to execute any code referring to that name will fail. Conversely, the function name doesn't need to be bound until the code referring to it is actually executed. So... > def g(): > return f() > def f(): > return 3 > print g() works because by the time g is *called*, both def statements have been executed, and both function names have therefore been bound. -- Greg