In this tutorial, We will learn the Python class method vs static method in detail. In a Python webinar, someone asked about the differences between the class method and the static method. I explored this topic and I will share my findings in this article. Let us learn more about this topic today.
Methods in Python
In Python, methods are functions defined within a class that describe the behaviors of an object. While instance methods operate on instances of the class, class methods and static methods serve different purposes.
Class Method in Python
A class method is a method that is bound to the class and not the instance of the class. It takes cls as its first parameter, which refers to the class itself, rather than an instance of the class. This allows class methods to modify class state that applies across all instances of the class.
To define a class method, you use the @classmethod decorator. Here’s an example:
class MyClass:
class_variable = "Hello, World!"
@classmethod
def class_method(cls):
return cls.class_variableIn this example, class_method can access class_variable directly through the cls parameter.
Check out Happy Birthday Code in Python
Characteristics of Python Class Methods
- Bound to the class, not the instance.
- Can access and modify class state.
- Defined with the
@classmethoddecorator.
Static Method in Python
A static method is a method that does not operate on an instance or class. It does not take self or cls as its first parameter. Static methods are defined using the @staticmethod decorator and can be called on the class itself or an instance of the class. They behave like plain functions but belong to the class’s namespace.
Here’s an example:
class MyClass:
@staticmethod
def static_method():
return "This is a static method"In this example, static_method does not access or modify the class state or instance state.
Read Difference Between Linear Search and Binary Search in Python
Characteristics of Python Static Methods
- Not bound to the class or instance.
- Cannot access or modify class or instance state.
- Defined with the
@staticmethoddecorator.
Key Difference Between Class Method and Static Method in Python
| Feature | Class Method | Static Method |
|---|---|---|
| Binding | Class (cls) | Neither class nor instance |
| Access | Can access and modify class state | Cannot access or modify class/instance state |
| Decorator | @classmethod | @staticmethod |
| Use Case | Factory methods, modifying class state | Utility functions, independent operations |
Check out How to Use the insert() Function in Python?
Use Cases
Let us go through some use cases of class methods and static methods in Python.
Usage of Python Class Methods
Class methods are particularly useful for factory methods that instantiate objects in different ways. They can also be used to modify class variables that affect all instances of the class.
Example:
class Pizza:
diameter = 12
def __init__(self, ingredients):
self.ingredients = ingredients
@classmethod
def set_diameter(cls, diameter):
cls.diameter = diameter
@classmethod
def margherita(cls):
return cls(["mozzarella", "tomatoes"])
# Usage
Pizza.set_diameter(16)
pizza = Pizza.margherita()
print(pizza.ingredients)
print(Pizza.diameter)Output:
['mozzarella', 'tomatoes']
16I have executed the above example code and added the screenshot below.

Read How to Use the arange() Function in Python?
Usage of Python Static Methods
Static methods are ideal for utility functions that perform a task in isolation. They can be used for operations that do not require access to class or instance data.
Example:
class Math:
@staticmethod
def add(x, y):
return x + y
# Usage
result = Math.add(5, 3)
print(result)Output:
8I have executed the above example code and added the screenshot below.

Check out How to Use the Python Pass Function?
Examples
Let us see some examples of class methods and static methods in Python.
Class Method Example
class Car:
base_price = 10000
def __init__(self, model, year):
self.model = model
self.year = year
@classmethod
def update_base_price(cls, new_price):
cls.base_price = new_price
@classmethod
def from_string(cls, car_string):
model, year = car_string.split('-')
return cls(model, int(year))
# Usage
Car.update_base_price(12000)
car1 = Car.from_string("Toyota-2020")
print(car1.model)
print(car1.year)
print(Car.base_price) Output:
Toyota
2020
12000Read Difference Between *args and **kwargs in Python
Static Method Example
class Temperature:
@staticmethod
def celsius_to_fahrenheit(celsius):
return (celsius * 9/5) + 32
@staticmethod
def fahrenheit_to_celsius(fahrenheit):
return (fahrenheit - 32) * 5/9
# Usage
temp_f = Temperature.celsius_to_fahrenheit(30)
temp_c = Temperature.fahrenheit_to_celsius(86)
print(temp_f)
print(temp_c) Output:
86.0
30.0Summary
| Feature | Class Method | Static Method |
|---|---|---|
| Binding | Class (cls) | Neither class nor instance |
| Access | Can access and modify class state | Cannot access or modify class/instance state |
| Decorator | @classmethod | @staticmethod |
| Use Case | Factory methods, modifying class state | Utility functions, independent operations |
Read How to Use the trim() Function in Python?
Conclusion
In this tutorial, I have explained the difference between the Python class method and static method. We saw about methods in Python, characteristics of class methods and static methods in Python , and key differences between class methods and static methods in Python, use cases and examples.
You may also like to read:
- How to Use the strip() Function in Python?
- How to Implement and Use the hash() Functions in Python?
- How to Use the map() Function in Python?

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.