static variables?
Mike Dean
klaatu at evertek.net
Wed Nov 20 16:28:06 EST 2002
Ahh, this makes everything clear. As usual, simple and elegant. But,
where is this documented in the Python docs?
-Michael
On Tuesday 19 November 2002 10:48 pm, Chad Netzer
<cnetzer at mail.arc.nasa.gov> wrote in comp.lang.python:
> On Tuesday 19 November 2002 18:59, Erik Max Francis wrote:
>
>> As for the "why," I think it's just a historical accident which is
>> too late to change now.
>
> Actually, it isn't so random as that. When you make a function with
> "def", it actually makes a function object right there, rather than
> making a promise
> to provide one later when linking. If you redefine a function (not
> allowed in many languages), python will happily make a new function
> object using the same name, etc.
>
> So, since the default argument is part of the definition, the default
> argument is actually created and bound, once, during the definition,
> not
> repeatedly during calling. But if you call a function repeatedly,
> giving an
> empty list argument each time, for example, a list IS created each
> time. It is all as you would expect, once you get into the proper
> mode of thinking about it.
>
More information about the Python-list
mailing list