Created
June 5, 2011 11:13
-
-
Save saghul/1008875 to your computer and use it in GitHub Desktop.
Default function arguments (non-mutable type)
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
In [1]: class Foo(object): | |
...: def __init__(self, bar=5): | |
...: self.bar = bar | |
...: | |
...: | |
In [2]: f1 = Foo() | |
In [3]: f2 = Foo() | |
In [4]: f1.bar | |
Out[4]: 5 | |
In [5]: f2.bar | |
Out[5]: 5 | |
In [6]: f1.bar += 1 | |
In [7]: f1.bar | |
Out[7]: 6 | |
In [8]: f2.bar | |
Out[8]: 5 | |
In [9]: id(f1.bar) | |
Out[9]: 12047040 | |
In [10]: id(f2.bar) | |
Out[10]: 12047064 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment