What is the difference between staticmethod and classmethod in Python?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Both @staticmethod and @classmethod define methods that you can call on the class itself, but they are not the same thing. A staticmethod gets no automatic first argument, while a classmethod receives the class as its first argument, usually named cls.
That difference determines when each one is appropriate. If the method needs class-aware behavior, use classmethod. If it is just a utility function that happens to live in the class namespace, use staticmethod.
@staticmethod: No self, No cls
A static method behaves like a plain function stored on the class.
The method does not receive an instance and does not receive the class automatically. It can still access global names or imported modules, but it has no built-in awareness of class state.
This makes staticmethod a good fit for helper logic that is conceptually related to the class but does not depend on object or class identity.
@classmethod: Gets the Class as cls
A class method receives the class itself.
Because it gets cls, a class method can:
- read class attributes
- modify class-level state
- create instances using the actual subclass that called it
That last use is why classmethod is common for factory methods.
Factory Method Example
Using cls(...) instead of hard-coding Person(...) makes the method subclass-friendly.
Why classmethod Helps with Inheritance
This prints Dog, not Animal, because cls refers to the class that invoked the method.
A staticmethod does not have that behavior automatically.
How They Behave When Called
Both decorators let you call the method on the class, and both can also be accessed through an instance. The important difference is still what gets passed automatically.
Calling through an instance does not suddenly make a static method receive self. It stays argument-free unless you pass something explicitly. A class method still receives the class, not the instance.
This is useful to remember because both methods are descriptors, but they bind differently.
When to Choose Which
Use @staticmethod when:
- the logic does not need
self - the logic does not need
cls - the method is just namespaced utility behavior
Use @classmethod when:
- the logic needs class attributes
- the method should respect subclasses
- you are building alternative constructors or factories
If the method needs instance state, it should usually be a normal instance method instead.
Common Pitfalls
The biggest mistake is using staticmethod for factory-style methods that really should be class-aware. That makes subclassing less flexible.
Another common issue is using classmethod even when the method does not need cls at all. That adds unnecessary coupling to the class.
People also sometimes think staticmethod is about performance. In practice, the design question is semantic: what information should the method receive automatically?
Finally, if a method needs instance attributes such as self.name, neither decorator is the right choice. Use a regular instance method.
Summary
- '
staticmethodgets no automatic first argument.' - '
classmethodreceives the class ascls.' - Use
staticmethodfor utility behavior that does not depend on class or instance state. - Use
classmethodfor class-aware logic and factory methods. - '
classmethodworks better with inheritance because it uses the calling class.' - If the method needs object state, use a normal instance method instead.

