Puzzling: local variable in recursive function made global?

andrew cooke andrew at acooke.org
Thu Mar 26 22:10:54 CET 2009


Peter Otten wrote:

> I would be surprised by the behaviour of Andrew's variant:
>
>>>> def append(item, items=None):
> ...     items = items or []
> ...     items.append(item)
> ...     return items
> ...
>>>> a = []
>>>> append("x", a)
> ['x']

ah that's a good point.  andrew








More information about the Python-list mailing list