Last active
August 29, 2015 14:20
-
-
Save mirekfranc/757c20e71813bef7fe56 to your computer and use it in GitHub Desktop.
default arguments evaluated once at function definition...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> def a(x=False, y=[]): | |
... if not x: | |
... y.append (5) | |
... else: | |
... print y | |
... | |
>>> a() | |
>>> a() | |
>>> a() | |
>>> a() | |
>>> a() | |
>>> a(True) | |
[5, 5, 5, 5, 5] | |
>>> a() | |
>>> a(True) | |
[5, 5, 5, 5, 5, 5] | |
>>> | |
>>> def b(x=False, y=None): | |
... if y is None: | |
... y=[] | |
... if not x: | |
... y.append (5) | |
... else: | |
... print y | |
... | |
>>> b() | |
>>> b() | |
>>> b() | |
>>> b(True) | |
[] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment