Somthing strange with list as default argument
Julien Sagnard
julien.sagnard.withoutthis at free.fr
Wed Sep 22 04:19:45 EDT 2004
Hi all,
When passing a list as default argument for a function, only one list is
created for all calls.
exemple:
>>> def f(a=[]):
... a.append("x")
... print a
...
>>> f()
['x']
>>> f()
['x', 'x']
>>> f()
['x', 'x', 'x']
>>> f()
['x', 'x', 'x', 'x']
>>>
I'm not found any reference of this. Is it a bug ?
I'm working on Windows 2000 with python 2.3.4
More information about the Python-list
mailing list