0

I don't understand the behavior of this code:

>>> def buggy(arg, result = []):
...     result.append(arg)
...     print(result)
...
>>> buggy('a')
['a']
>>> buggy('b')
['a', 'b']

It seems that result is persistent between calls of buggy(). Why is that? Local variables are not persistent in Python...

Arrigo
  • 251
  • 1
  • 3
  • 6

0 Answers0