Skip to content

Instantly share code, notes, and snippets.

@damianesteban
Created September 6, 2013 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damianesteban/6466838 to your computer and use it in GitHub Desktop.
Save damianesteban/6466838 to your computer and use it in GitHub Desktop.
Simple program that demonstrates when writing to a class attribute in Python.
# 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