Skip to content

Instantly share code, notes, and snippets.

@lig
Last active December 13, 2015 23:18
Show Gist options
  • Save lig/4990405 to your computer and use it in GitHub Desktop.
Save lig/4990405 to your computer and use it in GitHub Desktop.
"def foo(bar=[])" explained
lst = []
def foo1(bar=lst):
bar.append(1)
print(bar)
foo1()
foo1()
foo1()
def foo2(bar):
bar.append(1)
print(bar)
foo2(lst)
foo2(lst)
foo2(lst)
class Foo:
bar = []
ham = Foo()
spam = Foo()
ham.bar.append(1)
print(spam.bar)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment