Skip to content

Instantly share code, notes, and snippets.

@arkilis
Last active May 9, 2017 00:17
Show Gist options
  • Save arkilis/341bf667a577b04b8b3a58bce78809a6 to your computer and use it in GitHub Desktop.
Save arkilis/341bf667a577b04b8b3a58bce78809a6 to your computer and use it in GitHub Desktop.
python @classmethod @staticmethod and instance method
class Foo(object):
variable = 1
def method(self, param):
print "run instance method (%s,%s)" % (self, param)
@classmethod
def class_method1(cls, param):
print "run class method (%s,%s)" % (cls, param)
@classmethod
def class_method2(cls):
print cls.variable
@staticmethod
def static_method1(param):
print "run static method (%s)" % param
@staticmethod
def static_method2():
print variable
foo = Foo()
foo.method("instance method")
#Foo.method("instance method again")
foo.class_method1("class method 1")
foo.class_method2()
Foo.class_method1("class method 1 again")
Foo.class_method2()
foo.static_method1("static method 1")
foo.static_method2()
Foo.static_method1("static method 1 again")
Foo.static_method2()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment