Huh? func_defaults, default values in function calls
Fredrik Lundh
effbot at telia.com
Tue Apr 11 10:30:18 EDT 2000
Roger Baklund <roger at netconnect.no> wrote:
> I don't get it. Why isn't the dictionary reset to {'x':'a'} when i call
> the function the last time?
>
> >>> a.func_defaults
> ('', '', {'x': 'a', 'y': 'c'})
>
> Why is not {} the default for the z parameter?
read the fine manual:
http://www.python.org/doc/current/ref/function.html
Default parameter values are evaluated when the function
definition is executed. This means that the expression is
evaluated once, when the function is defined, and that
that same "pre-computed" value is used for each call.
(reading the entire page might help you understand why this
is by design, not by accident)
</F>
More information about the Python-list
mailing list