Difference between static and class methods in Python?

Better Stack Team
Updated on January 26, 2023

Class method

To create a class method, use the @classmethod decorator. Class methods receive the class as an implicit first argument, just like an instance method receives the instance. The class method is also bound to the class and not to the object of the class. Class methods also have access to class state and can modify class state.

class MyClass(object):
    def my_function(myClass, arg1, arg2, ...):

Static method

The static method does not receive an implicit first argument and it is also bound to the class and not to the object of the class. This method can’t access or modify the class state. In general, the static method knows nothing about the class it is bound to.

class MyClass(object):
    def my_function(arg1, arg2, ...):

Class methods are generally used to create factory functions, whereas static methods are used to create utility functions.

Got an article suggestion? Let us know
Explore more
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

We are hiring.

Software is our way of making the world a tiny bit better. We build tools for the makers of tomorrow.

Explore all positions →