Recommended Free Tools
Python’s @classmethod decorator makes the class—not an instance—the method’s implicit first argument. That lets a method work with class-level behavior or act as an alternate constructor, and it means an inherited class method receives the subclass when called through that subclass.
What does classmethod() do?
classmethod transforms a function into a class method. The method’s first parameter is conventionally named cls; Python supplies the relevant class automatically. The Python documentation describes the binding as analogous to an instance method receiving its instance, except a class method receives the class. See the Python built-in functions documentation.
As an Amazon Associate I earn from qualifying purchases.
In normal code, use the decorator form:
class User:
@classmethod
def guest(cls):
return cls("guest", is_active=True)
def __init__(self, name, is_active):
self.name = name
self.is_active = is_active
user = User.guest()
When User.guest() is called, cls is User. A class method can also be called through an instance, as in User().guest(); Python supplies the instance’s class, not the instance itself. If the method is inherited and invoked through a derived class, Python supplies that derived class.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →How class methods differ from instance and static methods
| Method kind | Implicit first argument | Use it when |
|---|---|---|
| Instance method | The instance, conventionally self |
The operation needs or changes per-object state. |
| Class method | The class, conventionally cls |
The operation needs the calling class or should construct an instance of that class. |
| Static method | None | The function belongs conceptually in the class namespace but needs neither an instance nor a class argument. |
The distinction is about binding, not simply access to class variables. A class method receives the class used for the call, so inherited methods can respond to subclasses. A static method receives no implicit argument. The Python descriptor guide explains these binding rules, including the class method behavior for calls through a class or an object.
#1 Best Overall
Use @classmethod for alternate constructors
An alternate constructor accepts a different representation of the data, then converts or validates it before creating an object. Use cls(...) when callers should be able to invoke the constructor through a subclass and get an instance of that subclass.
class DateParts:
def __init__(self, year, month, day):
self.year = year
self.month = month
self.day = day
@classmethod
def from_iso(cls, text):
year, month, day = map(int, text.split("-"))
return cls(year, month, day)
DateParts.from_iso("2026-10-05") creates an instance using the parsed components. If a subclass inherits from_iso and calls it through its own class, cls is that subclass; the constructor can therefore create the subclass rather than always creating DateParts. The descriptor guide demonstrates this subclass-preserving pattern with Dict.fromkeys.
Rank #2
Choosing the right method type
- Choose an instance method if the operation needs a particular object’s attributes or changes that object.
- Choose a class method if it needs the calling class, class-level behavior, or subclass-aware construction.
- Choose a static method only if neither the instance nor the class needs to be supplied. If a helper does not use class behavior, a plain function may communicate its purpose more clearly.
Common classmethod mistakes
- Calling the first parameter
self. The conventional name iscls, because the argument represents a class object, not an instance. - Hard-coding the base class in an alternate constructor. Returning
BaseClass(...)always constructs that named class. Returncls(...)when inherited calls should construct the subclass. - Using a class method for every helper. If a function needs neither class nor instance, a static method or a standalone function may be a clearer fit.
- Calling an instance method through the class without an instance. An instance method still needs an instance as its first argument; a class method instead receives the class automatically.
Python version notes: metadata and descriptor stacking
Python’s built-in documentation records several version-specific changes. Python 3.9 allowed a class method to wrap other descriptors, such as property(). That support was deprecated in Python 3.11 and removed in Python 3.13, so stacking @classmethod with @property is not a supported current pattern.
Python 3.10 changed class method metadata behavior: class methods began inheriting attributes such as __module__, __name__, __qualname__, __doc__, and __annotations__, and gained __wrapped__. Consult the version history in the built-in functions documentation and descriptor guide when working with code that targets older Python versions.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




