Skip to content

Instantly share code, notes, and snippets.

@gipi
Created October 24, 2011 12:18
Show Gist options
  • Select an option

  • Save gipi/1308887 to your computer and use it in GitHub Desktop.

Select an option

Save gipi/1308887 to your computer and use it in GitHub Desktop.
Python functions' default value is evaluated at function definition time.
def bad_append(new_item, a_list=[]):
"""
>>> print bad_append('one')
['one']
>>> print bad_append('two')
['one', 'two']
"""
a_list.append(new_item)
return a_list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment