Last active
May 9, 2017 00:17
-
-
Save arkilis/341bf667a577b04b8b3a58bce78809a6 to your computer and use it in GitHub Desktop.
python @classmethod @staticmethod and instance method
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
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