function with list argument defaulting to  - what's going on here???
mmoum at woh.rr.com
Sun Apr 15 03:23:16 CEST 2007
While trying to write a recursive function involving lists, I came
across some (to me) odd behavior which I don't quite understand. Here's
a trivial function showing the problem.
>>> def f(l, r = ):
for itm in l:
>>> a = [1,2,3]
[1, 2, 3]
[1, 2, 3, 1, 2, 3]
[1, 2, 3, 1, 2, 3, 1, 2, 3]
I know the function is quite artificial, but it's for illustration only.
Why is "r" not being reset to the empty list on subsequent calls? It
seems like it should be reinitialized when not explicitly provided.
Thanks in advance.
More information about the Python-list