top | item 10823743

(no title)

saltylicorice | 10 years ago

The problem is that the default argument is mutable.

  def f(a=[]):
    a.append('v')
    print a

  f(['ok']) # ['ok', 'v']
  f()       # ['v']
  f()       # ['v', 'v']

discuss

order