How to explain exactly what "def" does?
Greg Ewing (using news.cis.dfn.de)
me at privacy.net
Mon Feb 3 18:26:50 EST 2003
Roy Smith wrote:
> So, what exactly does "def foo" do? It seems that it does two things.
> First, it defines a function, and gives that function's __name__
> attribute the value "foo". At the same time, it also defines a name
> "foo" in the current namespace, and binds it to the function that was
> just defined. Is that a good (i.e. correct) way to explain it?
Looks pretty good. Instead of "defines a function" you could
say "creates a function object", which would help emphasise
that (1) functions are first-class objects and (2) the def
statement actually does something at run time, rather than
just being a static declaration.
More information about the Python-list
mailing list