What is the difference between an instance method, a class method, and a static method in Python?
Instance methods receive the instance as the first argument (`self`) and can read and modify instance state. Class methods receive the class as the first argument (`cls`) via `@classmethod` and are used for alternative constructors or class-level operations. Static methods receive no implicit argument and are plain functions namespaced inside a class.
How to think about it
How to think about it
The question is really: what implicit argument does Python inject, and why? Think of it as a routing decision Python makes before your function body runs.
- No decorator → instance method → Python passes the calling instance as
self @classmethod→ Python passes the class itself ascls@staticmethod→ Python passes nothing extra; it’s a plain function
All three in one class
Quick reference
| First arg | Decorator | Typical use | |
|---|---|---|---|
| Instance | self | none | Read/write instance state |
| Class | cls | @classmethod | Alternative constructors, class-level state |
| Static | — | @staticmethod | Utilities that don’t touch self or cls |
The key insight: why cls matters in @classmethod
Inside a @classmethod, using cls(...) instead of hardcoding Circle(...) means the method works correctly when subclassed. If Sphere extends Circle and calls Sphere.from_diameter(10), cls is Sphere so the factory returns a Sphere instance, not a Circle. Hardcoding the class name breaks this.