keyword arguments and **

Terry Reedy tjreedy at udel.edu
Fri Nov 15 13:09:58 EST 2002


"Alex Martelli" <aleax at aleax.it> wrote in message
news:w68B9.12486$744.448146 at news1.tin.it...
> Usual problem: when an argument (here, fields) has a default
> value that is mutable, that value is determined ONCE, when the
> def statement executes -- then that single value stays around
> (the function object references it), and if you mutate it you
> get such a "memory effect".

I would just add that if def occurs within a function called multiple
times, then default args are alse evaluated multiple times, but just
once for each execution of the def statemeant -- which is just once
for each function object produced.  (And if outer function is never
called, defaults are never evaluated.)

Terry J. Reedy





More information about the Python-list mailing list