side effects on *some* default parameters

Erik Max Francis max at
Thu Feb 13 02:55:31 CET 2003

Joe Grossberg wrote:

> Why does this happen? Specifically: when I call this function, how
> come
> aStr is reset to 'foo', but aList never reverts to an empty list?

Because in Python, default argument values are only created once.  The
FAQ addresses this, and it gets asked about once a week in the group.

 Erik Max Francis / max at /
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ If you can't fight and you can't flee, flow.
\__/ Robert Elliot
    Physics reference /
 A physics reference.

More information about the Python-list mailing list