What is the difference between a static method and class method in Python?

Are there any performance implications of declaring a class method versus a static method in Python?

  • This is a follow-up question to .

  • Answer:

    Both static method and class method are put into the 'class type' object at the same time (ie when the code of class is executed), so I think there is no difference in their performances (ie in speed). They both were separatly defined just because they could be used for different types of jobs . A classmethod is a cool way to do things with intantiation (the cls argument of it is callable as cls() thus running the __init__ method of class,so overriding in subclasses is possible) while staticmethod is good for dependency injection(using function of some other module in our class thorugh its instances). for eg, >>> class myList(list): def getListFromKeys(cls,dicti): return cls(dicti) getListFromKeys=classmethod(getListFromKeys) >>> a=myList() >>> b=a.getListFromKeys({'a':'apple'}) >>> b ['a'] >>> Static Method is to use some method declared in some other module into our class and use it by the instances of our class. There is no other way to call a method of class with the first argument not being cls or self

Muktabh Mayank at Quora Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.