Skip to content

Instantly share code, notes, and snippets.

@eungju
Last active December 20, 2015 22:29
Show Gist options
  • Select an option

  • Save eungju/6205176 to your computer and use it in GitHub Desktop.

Select an option

Save eungju/6205176 to your computer and use it in GitHub Desktop.
➜ ~ python self_and_cls.py
1 0
1 1
class Hello(object):
variable = 0
def __init__(self):
self.variable = 0
@classmethod
def increase_class_variable(cls):
cls.variable += 1
def increase_instance_variable(self):
self.variable += 1
o = Hello()
Hello.increase_class_variable()
print Hello.variable, o.variable
o.increase_instance_variable()
print Hello.variable, o.variable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment