Member-only story
What Are @classmethod and @staticmethod in Python?
Become a method master by learning the three method types of a class
In Python, a class can have methods, class methods, and static methods. But what is the difference between these three? How do they work?
Today, you are going to learn the key aspects and differences between the class-specific methods via useful examples.
Methods in Python
In Python, a method is a function that belongs to an object. A method is implemented inside a class and it takes the self
instance as an argument.
For example, a Weight
class can have a pounds()
method:
And you can call this method on a Weight
object:
m = Weight()
print(m.pounds())
Output:
22.05
Class Methods in Python
A class method is useful when you need a method that is not specific to an instance but involves the class somehow.