Created
September 6, 2013 17:16
-
-
Save damianesteban/6466838 to your computer and use it in GitHub Desktop.
Simple program that demonstrates when writing to a class attribute in Python.
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
# on line 11, we write to a CLASS attribute as opposed to an OBJECT attribute. | |
class Foo: | |
x = 42 | |
foo_1 = Foo() | |
foo_2 = Foo() | |
print(foo_1.a) # 42 | |
foo_1.a = 99 | |
print(foo_1.a) # 99 | |
print(foo_2.a) # 42 | |
Foo.a = 88 # changing the value of Foo's a | |
print(foo_1.a) # 99 (the value of foo_1's a) | |
print(foo_2.a) # 88 (the value of Foo's a) | |
del foo_1.a | |
print(foo_1.a) # 88 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment