Select Page
class SomeClass:
  def instancemethod(self):
    return 'instance method called', self

  @classmethod
  def classmethod(cls):
    return 'class method called', cls

  @staticmethod
  def staticmethod():
    return 'static method called'

Instantiate SomeClass

obj = SomeClass()

Instance Method

Passes obj as self parameter.

obj.instancemethod()

Passes obj as self parameter, same as above, without the syntactic sugar.

SomeClass.instancemethod(obj)

Class Method

It differs from the instance method as in the obj is not directly passed as a param, but Class SomeClass is passed directly as an object.

obj.classmethod()

Static Method

It differs from both instance and class methods as it takes no implicit parameter—neither self nor cls.

But, it can take the n-number of other parameters.

It works like regular methods but belongs to the class’s namespace.

Why static and class methods

Static and class methods have maintenance benefits as they communicate and tries to enforce the developer’s intent regarding how the class is designed. “