Python Instance Method vs Class Method: Differences
Learn the difference between Python instance methods and class methods, when to use each, and how they access instance and class state.

In Python, the choice between an instance method and a class method determines what the method receives as its first argument: the instance (self) or the class (cls). That distinction controls what data the method can access and what it can modify. Knowing the difference helps you design cleaner object-oriented code.
The Core Difference Between Instance and Class Methods
An instance method is bound to an instance of a class. When you call it on an object, Python automatically passes the instance as the first parameter, conventionally named self. This gives the method access to instance-specific attributes and other methods. A class method, decorated with @classmethod, is bound to the class itself. Its first parameter is the class, conventionally named cls, which lets it access class-level attributes and call other class methods, but it cannot directly access instance state.
Consider a simple Car class:
class Car:
wheels = 4 # class attribute
def __init__(self, color):
self.color = color # instance attribute
def describe(self):
return f"This car is {self.color} with {self.wheels} wheels."
@classmethod
def vehicle_type(cls):
return f"This is a vehicle with {cls.wheels} wheels."In this example, describe is an instance method; it uses self.color and self.wheels. vehicle_type is a class method; it uses cls.wheels. Both methods can access the class attribute, but only the instance method can access the instance attribute.
How Instance Methods Work
Instance methods are the default method type in Python. They are defined without a decorator and take self as the first argument. When you call car.describe(), Python passes the car object as self automatically, allowing the method to read and modify the instance's state.
car = Car("red")
print(car.describe()) # This car is red with 4 wheels.The key feature of an instance method is access to self, which represents the specific object. You can use it to change instance attributes, call other instance methods, or access instance properties. This is the primary way to encapsulate behavior that depends on the object's current state.
Instance methods are also inherited and can be overridden in subclasses. When you override an instance method, the subclass version receives the subclass instance, so it can access subclass-specific attributes.
How Class Methods Work
A class method is defined with the @classmethod decorator. Its first parameter is the class, cls, not an instance. You can call a class method on the class itself without creating an object, or on an instance; in both cases Python passes the class as the first argument.
print(Car.vehicle_type()) # This is a vehicle with 4 wheels.
car = Car("blue")
print(car.vehicle_type()) # This is a vehicle with 4 wheels.Class methods are useful for operations tied to the class but not to instance data. A common use is implementing alternative constructors. For example, you can create a Car from a string:
class Car:
def __init__(self, color):
self.color = color
@classmethod
def from_string(cls, s):
return cls(s.strip())
car = Car.from_string(" green ")
print(car.color) # greenBecause from_string receives cls, it can call cls(...) to create an instance of the actual class, which is especially useful in inheritance scenarios.
When to Use a Class Method Instead of an Instance Method
Choose a class method when the method needs to operate on the class itself, such as when:
- Creating alternative constructors that return instances, usually via
cls(...)so subclasses get the right class. - Accessing or modifying class-level attributes shared across all instances.
- Implementing factory methods that use
clsto instantiate the appropriate class, especially in inheritance. - Performing operations independent of any particular instance's state.
Use an instance method when the method's behavior depends on the specific instance's attributes. If you need to read or write self.something, use an instance method. If you only need class-level data or want to return a new instance, a class method is often cleaner.
For example, a class that tracks the total number of instances can use a class method to report that count:
class Employee:
count = 0
def __init__(self, name):
self.name = name
Employee.count += 1
@classmethod
def total_employees(cls):
return cls.countHere, total_employees is a class method because it only reads the class attribute count and does not need an instance.
Runtime Behavior and When It Matters
At runtime, the main difference is what gets bound: an instance method is bound to the object, while a class method is bound to the class. A class method can be called without creating an instance, which is useful when a method is meaningful at class level and creating an object just for the call would be unnecessary.
Inheritance is another place where the difference matters. When you call a class method on a subclass, cls refers to the subclass, not the base class. This allows polymorphic behavior. Instance methods also receive the subclass instance, so they can access subclass-specific attributes. The choice between them should be driven by the data the method needs, not by performance micro-optimizations.
Common Mistakes and Edge Cases
A frequent mistake is trying to access instance attributes from a class method. Since cls does not have access to self, attempting cls.color will raise an AttributeError unless color is a class attribute. Similarly, modifying class attributes through an instance method can be confusing because the method is bound to one object but changes state shared by all instances.
Another edge case is overriding class methods in subclasses. If you override a class method, the subclass version receives the subclass as cls. This is often desirable, but it can cause unexpected behavior if the base class method uses cls in a way that assumes the base class. Test such overrides carefully.
When a class method calls another class method, use cls.method() instead of the class name directly. That ensures the subclass's override is used when the method is inherited.
class Base:
@classmethod
def create(cls):
return cls()
@classmethod
def make(cls):
return cls.create() # uses cls, not Base
class Child(Base):
pass
c = Child.make()
print(type(c)) # <class '__main__.Child'>Decision Criteria for Choosing the Right Method Type
Use an instance method when the method must read or modify the instance's state (self.attribute). Use a class method when the method needs class-level data (cls.attribute) or a factory pattern that creates an instance. If the method needs neither, consider a static method (@staticmethod), which receives no automatic first argument.
A practical rule: if you catch yourself writing self.__class__ inside an instance method to access class-level behavior, a class method may be a clearer alternative. Conversely, if you need self to read an instance attribute, an instance method is required.
For maintainability, class methods make the class's intent explicit. They signal that the method is independent of instance state, which can simplify testing and reuse. Instance methods are the default and are appropriate for most behavior that depends on an object's data.
Inheritance also matters. When you expect subclasses to override behavior, class methods are often more flexible because they receive the subclass as cls. Instance methods receive the subclass instance, which also works, but class methods can be called without an instance, which can be useful in generic code.
Ultimately, the choice is about clarity and the data you need. Instance methods work best for instance state, class methods for class state or factory behavior.
Try matching browser tools
All toolsSmall utilities that fit Python work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related Python guides
All Python guidesPython iter(): How the Built-in Function Works
Explains Python's iter() built-in: how it creates iterators, the two-argument sentinel form, custom iterator classes, and common edge cases.
Python Pika: Queues, Exchanges, Routing Keys, and Acknowledgements
Learn how to use Python's Pika client with RabbitMQ: declare queues and exchanges, publish with routing keys, consume messages, and handle acknowledgements reliably.
Python Kafka: kafka-python vs Confluent Client
python kafka python vs confluent kafka: Compare kafka-python and Confluent Kafka Python clients: API differences, performance, feature coverage, and when to choose eac...
Python Kafka Offsets, Partitions, and Manual Commits
Learn how Kafka offsets and partitions work and how to manually commit offsets in Python consumers with kafka-python and confluent-kafka. Covers sync vs async commits, rebalances, and seeking.
More in Python
All Python guidesThe guides filed next to this one in Python, in library order.