In this answer, we have explained about difference between staticmethod and classmethod. Maybe a bit of example code will help: Notice the difference in the call signatures of foo, class_foo and static_foo:
1 2 3 4 5 6 7 8 9 10 11 12 13 | class A(object): def foo(self, x): print "executing foo(%s, %s)" % (self, x) @classmethod def class_foo(cls, x): print "executing class_foo(%s, %s)" % (cls, x) @staticmethod def static_foo(x): print "executing static_foo(%s)" % x a = A() |
Below is the usual way an object instance calls a method. The object instance, a, is implicitly passed as the first argument.
1 2 | a.foo(1) # executing foo(<__main__.A object at 0xb7dbef0c>,1) |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.