Every method you've likely written inside a Python class so far has been a regular instance method — one that takes self and works with a specific object's data. But Python also offers two other kinds of methods, marked with @staticmethod and @classmethod, each meant for cases where a method doesn't need — or needs something different from — a particular instance.
Instance Methods: The Default
An instance method takes self as its first parameter and can read or modify that specific object's attributes. This is what you use the vast majority of the time.
class Circle:
def __init__(self, radius):
self.radius = radius
def area(self): # instance method — needs self.radius
return round(3.14159 * self.radius ** 2, 2)
@staticmethod: No Access to self or the Class
A static method doesn't receive self or the class at all — it behaves like a plain function that just happens to live inside the class's namespace, usually because it's logically related to the class even though it doesn't need any of its data.
class Circle:
def __init__(self, radius):
self.radius = radius
@staticmethod
def is_valid_radius(value):
# doesn't need self — just validates a number
return value > 0
print(Circle.is_valid_radius(5))
print(Circle.is_valid_radius(-2))
Output:
True
False
@classmethod: Access to the Class, Not a Specific Instance
A class method takes cls (the class itself) instead of self. It's most commonly used for alternative constructors — ways to build an instance from data that doesn't match the normal __init__ signature.
class Circle:
def __init__(self, radius):
self.radius = radius
@classmethod
def from_diameter(cls, diameter):
# an alternative way to build a Circle, using cls instead of Circle directly
return cls(diameter / 2)
c = Circle.from_diameter(10)
print(c.radius)
Output:
5.0
Quick Decision Guide
Use an instance method when you need to read or change a specific object's data. Use a @classmethod when you need the class itself (commonly for alternative constructors, or for behavior shared across all instances that still needs to know which class it's on, important in inheritance). Use a @staticmethod when the method is just related to the class conceptually, but genuinely needs neither self nor cls.
