def X(l=[]): weirdness. Python bug ?

Bart van Deenen bart at
Fri Aug 22 11:13:52 CEST 2008

Hi all.

I've stumbled onto a python behavior that I don't understand at all.

Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) 

# function 
def X(l=[]):
   print l

# first call of X

#second call of X
[1, 1]

Where does the list parameter 'l' live between the two successive calls of X(). 
Why is it not recreated with an empty list?
Is this correct behavior or is it a Python bug?
Does anyone have any pointers to the language documentation where this behavior is described?

Thanks all

Bart van Deenen

More information about the Python-list mailing list