Gotcha in default arguments

>>> def test(arg=[]):
...     arg.append('hi')
...     print arg
...
>>> test()
['hi']
>>> test()
['hi', 'hi']
>>> test()
['hi', 'hi', 'hi']

Found this one here.

Advertisements