+ 3

When should one use a classmethod instead of a static method?

5th Apr 2016, 9:50 PM
Shadow3097
2 Answers
+ 6
A staticmethod is a method that knows nothing about the class or instance it was called on. It just gets the arguments that were passed, no implicit first argument. It is basically useless in Python - you can just use a module function instead of a staticmethod. A classmethod, on the other hand, is a method that gets passed the class it was called on, or the class of the instance it was called on, as first argument.
23rd May 2016, 12:18 PM
James Flanders
0
Actually, you don't answer the question and a static method is not useless, it just doesn't use any information in the instance dictionary. When you work with clouds, for instance, you have to convert pressures to different units. How do you do that easily with module functions ?
30th Aug 2016, 10:15 PM
Amaras A
Amaras A - avatar