Somthing strange with list as default argument
Alex Martelli
aleaxit at yahoo.com
Wed Sep 22 04:33:53 EDT 2004
Julien Sagnard <julien.sagnard.withoutthis at free.fr> wrote:
> Hi all,
>
> When passing a list as default argument for a function, only one list is
> created for all calls.
Right.
> I'm not found any reference of this. Is it a bug ?
No, you just didn't look in the right places, for example in the
Tutorial which is the recommended first reading for new Python users.
Under 4.7.1 the Tutorial says:
"""
Important warning: The default value is evaluated only once. This makes
a difference when the default is a mutable object such as a list,
dictionary, or instances of most classes.
"""
The 'Important warning' is in bold, too...
Alex
More information about the Python-list
mailing list