Skip to content

Instantly share code, notes, and snippets.

@ryaninhust
Created November 13, 2013 15:36
Show Gist options
  • Save ryaninhust/7451047 to your computer and use it in GitHub Desktop.
Save ryaninhust/7451047 to your computer and use it in GitHub Desktop.
Show Puzzle about Python Class Attributes and Instance Attributes
>>> class Case(object):
... a = []
... def show_attribute(self):
... print self.a
>>> Case.a
[]
>>> case = Case()
>>> case.a
[]
>>> case.a = 123
>>> case.a
123
>>> case.show_attribute()
123
>>> case_2 = Case()
>>> case_2.a
[]
>>> case_2.show_attribute()
[]
>>> case_2.a.append(123)
>>> case_2.show_attribute()
[123]
>>> Case.a
[123]
>>> case_3 = Case()
>>> case_3.a
[123]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment