pitfall for your amusement

Jeff Epler jepler at unpythonic.net
Tue Nov 12 22:01:05 EST 2002


On Tue, Nov 12, 2002 at 06:52:02PM -0800, Terry Hancock wrote:
> What would I have to do for this to be a problem? (as it happens, I have used 
> this kind of default before, so I would like to understand the pitfall!)

Mutate the list in the function, as
    def stupid(i, l=[]):
	l.append(i)
	return l

>>> stupid(1, [])
[1]
>>> stupid(1)
[1]
>>> stupid(2, [])
[2]
>>> stupid(2)
[1, 2]

Jeff




More information about the Python-list mailing list