Though classmethod and staticmethod are quite similar, there's a slight difference in usage for both entities: classmethod must have a reference to a class object as the first parameter, whereas staticmethod can have no parameters at all.

Example

class Date(object):
    
    def __init__(self, day=0, month=0, year=0):
        self.day = day
        self.month = month
        self.year = year

    @classmethod
    def from_string(cls, date_as_string):
        day, month, year = map(int, date_as_string.split('-'))
        date1 = cls(day, month, year)
        return date1

    @staticmethod
    def is_date_valid(date_as_string):
        day, month, year = map(int, date_as_string.split('-'))
        return day <= 31 and month <= 12 and year <= 3999

date2 = Date.from_string('11-09-2012')
is_date = Date.is_date_valid('11-09-2012')

Explanation

Let's assume an example of a class, dealing with date information (this will be our boilerplate):

class Date(object):
    
    def __init__(self, day=0, month=0, year=0):
        self.day = day
        self.month = month
        self.year = year

This class obviously could be used to store information about certain dates (without timezone information; let's assume all dates are presented in UTC).

Here we have __init__, a typical initializer of Python class instances, which receives arguments as a typical instance method, having the first non-optional argument (self) that holds a reference to a newly created instance.

Class Method

We have some tasks that can be nicely done using classmethods.

Let's assume that we want to create a lot of Date class instances having date information coming from an outer source encoded as a string with format 'dd-mm-yyyy'. Suppose we have to do this in different places in the source code of our project.

So what we must do here is:

  1. Parse a string to receive day, month and year as three integer variables or a 3-item tuple consisting of that variable.
  2. Instantiate Date by passing those values to the initialization call.

This will look like:

day, month, year = map(int, string_date.split('-'))
date1 = Date(day, month, year)

For this purpose, C++ can implement such a feature with overloading, but Python lacks this overloading. Instead, we can use classmethod. Let's create another constructor.

    @classmethod
    def from_string(cls, date_as_string):
        day, month, year = map(int, date_as_string.split('-'))
        date1 = cls(day, month, year)
        return date1

date2 = Date.from_string('11-09-2012')

Let's look more carefully at the above implementation, and review what advantages we have here:

  1. We've implemented date string parsing in one place and it's reusable now.
  2. Encapsulation works fine here (if you think that you could implement string parsing as a single function elsewhere, this solution fits the OOP paradigm far better).
  3. cls is the class itself, not an instance of the class. It's pretty cool because if we inherit our Date class, all children will have from_string defined also.

Static method

What about staticmethod? It's pretty similar to classmethod but doesn't take any obligatory parameters (like a class method or instance method does).

Let's look at the next use case.

We have a date string that we want to validate somehow. This task is also logically bound to the Date class we've used so far, but doesn't require instantiation of it.

Here is where staticmethod can be useful. Let's look at the next piece of code:

    @staticmethod
    def is_date_valid(date_as_string):
        day, month, year = map(int, date_as_string.split('-'))
        return day <= 31 and month <= 12 and year <= 3999

# usage:
is_date = Date.is_date_valid('11-09-2012')

So, as we can see from usage of staticmethod, we don't have any access to what the class is---it's basically just a function, called syntactically like a method, but without access to the object and its internals (fields and other methods), which classmethod does have.

Answer from Rostyslav Dzinko on Stack Overflow
🌐
W3Schools
w3schools.com › PYTHON › python_class_methods.asp
Python Class Methods
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... Methods are functions that belong to a class.
🌐
GeeksforGeeks
geeksforgeeks.org › python › classmethod-in-python
classmethod() in Python - GeeksforGeeks
July 11, 2025 - The classmethod() is an inbuilt function in Python, which returns a class method for a given function. This means that classmethod() is a built-in Python function that transforms a regular method into a class method. When a method is defined using the @classmethod decorator (which internally calls classmethod()), the method is bound to the class and not to an instance of the class.
Discussions

python - Meaning of @classmethod and @staticmethod for a beginner - Stack Overflow
What do @classmethod and @staticmethod mean in Python, and how are they different? When should I use them, why should I use them, and how should I use them? As far as I understand, @classmethod tells a class that it's a method which should be inherited into subclasses, or... More on stackoverflow.com
🌐 stackoverflow.com
What is @classmethod in python and why we need this , when to use it?
A "normal" method is tied to an object instantiated from the class. A class method is called from the class itself instead of an instance. The first argument of a class method is the class itself (usually called cls instead of self because of that). One use is e.g. mass instantiation. Let's say you have a list of whatever that you want to parse and turn into instances of your class. You could manually loop over the list and call the constructor a lot, or you could make a class method that does it for you and returns a lit of instances, so you can easily re-use end extend it in sub classes and such. More on reddit.com
🌐 r/AskComputerScience
3
0
February 19, 2022
terminology - What are "class methods" and "instance methods", in Python? - Software Engineering Stack Exchange
The behaviour of class method objects upon such retrieval is described above, under “User-defined methods”. Class method objects are created by the built-in classmethod() constructor. What is the difference between @staticmethod and @classmethod in Python? More on softwareengineering.stackexchange.com
🌐 softwareengineering.stackexchange.com
December 29, 2015
When to Use Class Methods vs. Functions?
If you have a class, then the things that mutate the state of objects of that class should be methods defined in the class (and therefore, attributes of the object.) That's the point of a class - you're defining the type of an object whose state can change, and you're putting all of the code that can change that state in the same place so it's all nice and organized and you're not hunting all over your codebase to fix bugs. That's pretty much the universal rule - functions (that is, functions that aren't methods of classes) generally shouldn't operate by side-effect if you can help it. A "side-effect" is when the body of the function mutates the state of one of its parameter values. Ideally, one tries not to do this. More on reddit.com
🌐 r/learnpython
15
2
January 12, 2021
🌐
Python documentation
docs.python.org › 3 › tutorial › classes.html
9. Classes — Python 3.14.3 documentation
As is true for modules, classes partake of the dynamic nature of Python: they are created at runtime, and can be modified further after creation. In C++ terminology, normally class members (including the data members) are public (except see below Private Variables), and all member functions are virtual. As in Modula-3, there are no shorthands for referencing the object’s members from its methods: the method function is declared with an explicit first argument representing the object, which is provided implicitly by the call.
Top answer
1 of 12
3059

Though classmethod and staticmethod are quite similar, there's a slight difference in usage for both entities: classmethod must have a reference to a class object as the first parameter, whereas staticmethod can have no parameters at all.

Example

class Date(object):
    
    def __init__(self, day=0, month=0, year=0):
        self.day = day
        self.month = month
        self.year = year

    @classmethod
    def from_string(cls, date_as_string):
        day, month, year = map(int, date_as_string.split('-'))
        date1 = cls(day, month, year)
        return date1

    @staticmethod
    def is_date_valid(date_as_string):
        day, month, year = map(int, date_as_string.split('-'))
        return day <= 31 and month <= 12 and year <= 3999

date2 = Date.from_string('11-09-2012')
is_date = Date.is_date_valid('11-09-2012')

Explanation

Let's assume an example of a class, dealing with date information (this will be our boilerplate):

class Date(object):
    
    def __init__(self, day=0, month=0, year=0):
        self.day = day
        self.month = month
        self.year = year

This class obviously could be used to store information about certain dates (without timezone information; let's assume all dates are presented in UTC).

Here we have __init__, a typical initializer of Python class instances, which receives arguments as a typical instance method, having the first non-optional argument (self) that holds a reference to a newly created instance.

Class Method

We have some tasks that can be nicely done using classmethods.

Let's assume that we want to create a lot of Date class instances having date information coming from an outer source encoded as a string with format 'dd-mm-yyyy'. Suppose we have to do this in different places in the source code of our project.

So what we must do here is:

  1. Parse a string to receive day, month and year as three integer variables or a 3-item tuple consisting of that variable.
  2. Instantiate Date by passing those values to the initialization call.

This will look like:

day, month, year = map(int, string_date.split('-'))
date1 = Date(day, month, year)

For this purpose, C++ can implement such a feature with overloading, but Python lacks this overloading. Instead, we can use classmethod. Let's create another constructor.

    @classmethod
    def from_string(cls, date_as_string):
        day, month, year = map(int, date_as_string.split('-'))
        date1 = cls(day, month, year)
        return date1

date2 = Date.from_string('11-09-2012')

Let's look more carefully at the above implementation, and review what advantages we have here:

  1. We've implemented date string parsing in one place and it's reusable now.
  2. Encapsulation works fine here (if you think that you could implement string parsing as a single function elsewhere, this solution fits the OOP paradigm far better).
  3. cls is the class itself, not an instance of the class. It's pretty cool because if we inherit our Date class, all children will have from_string defined also.

Static method

What about staticmethod? It's pretty similar to classmethod but doesn't take any obligatory parameters (like a class method or instance method does).

Let's look at the next use case.

We have a date string that we want to validate somehow. This task is also logically bound to the Date class we've used so far, but doesn't require instantiation of it.

Here is where staticmethod can be useful. Let's look at the next piece of code:

    @staticmethod
    def is_date_valid(date_as_string):
        day, month, year = map(int, date_as_string.split('-'))
        return day <= 31 and month <= 12 and year <= 3999

# usage:
is_date = Date.is_date_valid('11-09-2012')

So, as we can see from usage of staticmethod, we don't have any access to what the class is---it's basically just a function, called syntactically like a method, but without access to the object and its internals (fields and other methods), which classmethod does have.

2 of 12
1039

Rostyslav Dzinko's answer is very appropriate. I thought I could highlight one other reason you should choose @classmethod over @staticmethod when you are creating an additional constructor.

In the example, Rostyslav used the @classmethod from_string as a Factory to create Date objects from otherwise unacceptable parameters. The same can be done with @staticmethod as is shown in the code below:

class Date:
  def __init__(self, month, day, year):
    self.month = month
    self.day   = day
    self.year  = year


  def display(self):
    return "{0}-{1}-{2}".format(self.month, self.day, self.year)


  @staticmethod
  def millenium(month, day):
    return Date(month, day, 2000)

new_year = Date(1, 1, 2013)               # Creates a new Date object
millenium_new_year = Date.millenium(1, 1) # also creates a Date object. 

# Proof:
new_year.display()           # "1-1-2013"
millenium_new_year.display() # "1-1-2000"

isinstance(new_year, Date) # True
isinstance(millenium_new_year, Date) # True

Thus both new_year and millenium_new_year are instances of the Date class.

But, if you observe closely, the Factory process is hard-coded to create Date objects no matter what. What this means is that even if the Date class is subclassed, the subclasses will still create plain Date objects (without any properties of the subclass). See that in the example below:

class DateTime(Date):
  def display(self):
      return "{0}-{1}-{2} - 00:00:00PM".format(self.month, self.day, self.year)


datetime1 = DateTime(10, 10, 1990)
datetime2 = DateTime.millenium(10, 10)

isinstance(datetime1, DateTime) # True
isinstance(datetime2, DateTime) # False

datetime1.display() # returns "10-10-1990 - 00:00:00PM"
datetime2.display() # returns "10-10-2000" because it's not a DateTime object but a Date object. Check the implementation of the millenium method on the Date class for more details.

datetime2 is not an instance of DateTime? WTF? Well, that's because of the @staticmethod decorator used.

In most cases, this is undesired. If what you want is a Factory method that is aware of the class that called it, then @classmethod is what you need.

Rewriting Date.millenium as (that's the only part of the above code that changes):

@classmethod
def millenium(cls, month, day):
    return cls(month, day, 2000)

ensures that the class is not hard-coded but rather learnt. cls can be any subclass. The resulting object will rightly be an instance of cls.
Let's test that out:

datetime1 = DateTime(10, 10, 1990)
datetime2 = DateTime.millenium(10, 10)

isinstance(datetime1, DateTime) # True
isinstance(datetime2, DateTime) # True


datetime1.display() # "10-10-1990 - 00:00:00PM"
datetime2.display() # "10-10-2000 - 00:00:00PM"

The reason is, as you know by now, that @classmethod was used instead of @staticmethod

🌐
StrataScratch
stratascratch.com › blog › mastering-python-class-methods-a-practical-guide
Mastering Python Class Methods: A Practical Guide - StrataScratch
April 19, 2024 - A class method is an instance method based on an instance of the class or an object. You can use the self method to link the function to the instance to access the instance attributes or call the instance method.
🌐
Reddit
reddit.com › r/askcomputerscience › what is @classmethod in python and why we need this , when to use it?
r/AskComputerScience on Reddit: What is @classmethod in python and why we need this , when to use it?
February 19, 2022 - It is a way of binding a function call to a class name, it serves an organizational need. It gathers methods in a namespace. Basic object oriented design. C++ uses namespaces, python uses packages and class methods, Java uses ...
Find elsewhere
🌐
Python documentation
docs.python.org › 3 › library › functions.html
Built-in Functions — Python 3.14.3 documentation
2 weeks ago - For other containers see the built-in list, set, and tuple classes, as well as the collections module. ... Without arguments, return the list of names in the current local scope. With an argument, attempt to return a list of valid attributes for that object. If the object has a method named __dir__(), this method will be called and must return the list of attributes.
🌐
Real Python
realpython.com › ref › builtin-functions › classmethod
classmethod() | Python’s Built-in Functions – Real Python
The built-in classmethod() function is a decorator that transforms a method into a class method. A class method receives the class itself as its first argument, enabling it to access or modify class-level data rather than instance data.
Top answer
1 of 3
56

The short answer

  • an instance method knows its instance (and from that, its class)
  • a class method knows its class
  • a static method doesn't know its class or instance

The long answer

Class methods

A class method is one that belongs to the class as a whole. It doesn't require an instance. Instead, the class will automatically be sent as the first argument. A class method is declared with the @classmethod decorator.

For example:

class Foo(object):
    @classmethod
    def hello(cls):
        print("hello from %s" % cls.__name__)
Foo.hello()
-> "Hello from Foo"
Foo().hello()
-> "Hello from Foo"

Instance Methods

On the other hand, an instance method requires an instance in order to call it, and requires no decorator. This is by far the most common type of method.

class Foo(object):
    def hello(self):
        print("hello from %s" % self.__class__.__name__)
Foo.hello()
-> TypeError: hello() missing 1 required positional argument: 'self'

(note: the above is with python3; with python2 you'll get a slightly different error)

Static methods

A static method is similar to a class method, but won't get the class object as an automatic parameter. It is created by using the @staticmethod decorator.

class Foo(object):
    @staticmethod
    def hello(cls):
        print("hello from %s" % cls.__name__)

Foo.hello()
-> TypeError: hello() missing 1 required positional argument: 'cls'

Documentation links

Here are links to the relevant python3 documentaton:

  • https://docs.python.org/3.5/library/functions.html#classmethod
  • https://docs.python.org/3.5/library/functions.html#staticmethod

The data model documentation has this to say about the difference between class methods and static methods:

Static method objects Static method objects provide a way of defeating the transformation of function objects to method objects described above. A static method object is a wrapper around any other object, usually a user-defined method object. When a static method object is retrieved from a class or a class instance, the object actually returned is the wrapped object, which is not subject to any further transformation. Static method objects are not themselves callable, although the objects they wrap usually are. Static method objects are created by the built-in staticmethod() constructor.

Class method objects A class method object, like a static method object, is a wrapper around another object that alters the way in which that object is retrieved from classes and class instances. The behaviour of class method objects upon such retrieval is described above, under “User-defined methods”. Class method objects are created by the built-in classmethod() constructor.

Related questions

  • What is the difference between @staticmethod and @classmethod in Python? (stackoverflow)
2 of 3
10

What are “class methods” and “instance methods”, in Python?

  • An "instance method" uses the information contained in the instance to figure out what value to return (or which side-effect to do). These are very common.

  • A "class method" uses information about the class (and not an instance of that class) to affect what it does (they're typically used to create new instances as alternative constructors, and thus aren't incredibly common).

  • A "static method" doesn't use any information about the class or instance to calculate what it does. It is usually just in the class for convenience. (As such, these aren't very common either.)

A Function of X

Remember math class, "y is a function of x, f(x)?" Let's apply that in code:

y = function(x)

Implied by the above is that since x may change, y may change when x changes. This is what is meant when we say that "y is a function of x"

What will y be when z is 1? 2? 'FooBarBaz'?

y is not a function of z, so z can be anything and not affect the outcome of the function assuming our function is a pure function. (If it accesses z as a global variable, then it's not a pure function - this is what is meant by functional purity.)

Keep the above in mind as you read the following descriptions:

Instance Methods

An instance method is function that is a function of an instance. The function accepts the instance implicitly as an argument to it, and the instance is used by the function to determine the output of the function.

A built-in example of an instance method is str.lower:

>>> 'ABC'.lower()
'abc'

str.lower is implicitly called on the instance of the string, and it uses the information contained in the instance to figure out which new string to return.

We can also explicitly pass the instance to the method looked up from the str class:

>>> str.lower('ABC')
'abc'

Class Methods:

Remember, in Python, everything is an object. That means the class is an object, and can be passed as an argument to a function.

A class method is a function that is a function of the class. It accepts the class as an argument to it.

A builtin example is dict.fromkeys:

>>> dict.fromkeys('ABC')
{'C': None, 'B': None, 'A': None}

The function implicitly knows its own class, the function uses the class to affects the output of the function, and it creates a new one of that class from the iterable. An OrderedDict demonstrates this when using the same method:

>>> from collections import OrderedDict
>>> OrderedDict.fromkeys('ABC')
OrderedDict([('A', None), ('B', None), ('C', None)])

The class method uses information about the class (and not an instance of that class) to affect what type of class to return.

We can also look up the method directly from the class namespace (a simple dictionary) and pass the class object explicitly:

>>> vars(dict)'fromkeys'
{'A': None, 'B': None, 'C': None}
>>> vars(dict)'fromkeys'
OrderedDict([('A', None), ('B', None), ('C', None)])

Static Methods

You mention a method that "doesn't know its class" - this is a static method in Python. It is merely attached for convenience to the class object. It could optionally be a separate function in another module, but its call signature would be the same.

A static method is a function of neither the class nor the object.

A built-in example of a static method is str.maketrans from Python 3.

>>> str.maketrans('abc', 'bca')
{97: 98, 98: 99, 99: 97}

Given a couple of arguments, it makes a dictionary that is not a function of its class.

It is convenient because str is always available in the global namespace, so you can easily use it with the translate function:

>>> 'abracadabra'.translate(str.maketrans('abc', 'bca'))
'bcrbabdbcrb'

In Python 2, you have to access it from the string module:

>>> 'abracadabra'.translate(str.maketrans('abc', 'bca'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: type object 'str' has no attribute 'maketrans'
>>> import string
>>> 'abracadabra'.translate(string.maketrans('abc', 'bca'))
'bcrbabdbcrb'

And now, in Python 3.10, thanks to issue 43682 being resolved, we can indeed simply look up the method/function in the class namespace and use it as a function:

>>> vars(str)'maketrans'
{97: 65, 98: 66, 99: 67}

Example

class AClass(object):
    """In Python, a class may have several types of methods: 
    instance methods, class methods, and static methods
    """

    def an_instance_method(self, x, y, z=None):
        """this is a function of the instance of the object
        self is the object's instance
        """
        return self.a_class_method(x, y)

    @classmethod
    def a_class_method(cls, x, y, z=None):
        """this is a function of the class of the object
        cls is the object's class
        """
        return cls.a_static_method(x, y, z=z)

    @staticmethod
    def a_static_method(x, y, z=None):
        """this is neither a function of the instance or class to 
        which it is attached
        """
        return x, y, z

Let's instantiate:

>>> instance = AClass()

Now the instance can call all of the methods:

>>> instance.an_instance_method('x', 'y')
('x', 'y', None)
>>> instance.a_static_method('x', 'y')
('x', 'y', None)
>>> instance.a_class_method('x', 'y')
('x', 'y', None)

But the class is not usually intended to call the instance method, though it is expected to call the others:

>>> AClass.a_class_method('x', 'y')
('x', 'y', None)
>>> AClass.a_static_method('x', 'y')
('x', 'y', None)
>>> AClass.an_instance_method('x', 'y')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: an_instance_method() missing 1 required positional argument: 'y'

You would have to explicitly pass the instance to call the instance method:

>>> AClass.an_instance_method(instance, 'x', 'y')
('x', 'y', None)
🌐
Real Python
realpython.com › instance-class-and-static-methods-demystified
Python's Instance, Class, and Static Methods Demystified – Real Python
March 17, 2025 - In this tutorial, you'll compare Python's instance methods, class methods, and static methods. You'll gain an understanding of when and how to use each method type to write clear and maintainable object-oriented code.
🌐
Medium
medium.com › @imshivam077 › day-36-class-method-in-python-758a0b963e62
Day-36 Class Method In Python. Python Class Methods: An Introduction | by Shivam Shukla | Medium
January 25, 2024 - A class method is a type of method that is bound to the class and not the instance of the class. In other words, it operates on the class as a whole, rather than on a specific instance of the class.
🌐
AlgoMaster
algomaster.io › learn › python › class-methods
Class Methods | Python | AlgoMaster.io | AlgoMaster.io
January 3, 2026 - Class methods are methods that are bound to the class rather than its instances. This means they can be called on the class itself, rather than needing an instance of the class. In Python, you define a class method using the @classmethod decorator, ...
🌐
Medium
medium.com › @ebimsv › mastering-classes-in-python-2-class-and-instance-variables-methods-7e48524bc673
🐍 Python for AI: Week 7-Classes in Python: 2. Different Types of Methods in Python Classes | by Ebrahim Mousavi | Medium
October 6, 2025 - We use a staticmethod (calculate_speed) to perform a calculation that doesn't depend on the class or instance state. This method is not bound to the class or instances and can't access class or instance attributes. This example demonstrates how classmethod and staticmethod can be used in a Python class to perform different tasks.
🌐
Programiz
programiz.com › python-programming › methods › built-in › classmethod
Python classmethod()
Become a certified Python programmer. Try Programiz PRO! ... The classmethod() method returns a class method for the given function.
🌐
Codecademy
codecademy.com › learn › cspath-python-objects › modules › cspath-python-classes › cheatsheet
Python Objects: Python: Classes Cheatsheet | Codecademy
Class variables are accessed with the instance.variable or class_name.variable syntaxes. ... In Python, the .__init__() method is used to initialize a newly created object.
🌐
Reddit
reddit.com › r/learnpython › when to use class methods vs. functions?
r/learnpython on Reddit: When to Use Class Methods vs. Functions?
January 12, 2021 -

I am new to python and object oriented programming in general, and so far, one thing I struggle with is when to define a method for a class vs a general function callable by any object (e.g. object.method() vs method(object)). It seems to me that the general rule is if different classes require a different algorithm to be called, then it makes sense to define it as a class method so that the switching will happen automatically by class and the code will be much cleaner. Is that the basic idea? Or is it more related to whether the default argument is going to be "self" anyway?

Also, in terms of when to define classes in general, it seems to me that if one variable name should hold many different fields (and those fields are desired to be able to be changed), then it is a good idea to make a class. Does that sound right?

Any other advice would be appreciated,

🌐
Tutorialspoint
tutorialspoint.com › home › python › python class methods
Python Class Methods
February 21, 2009 - A Python class method is a method that is bound to the class and not to the instance of the class.
🌐
Vultr Docs
docs.vultr.com › python › built-in › classmethod
Python classmethod() - Create Class Method | Vultr Docs
December 5, 2024 - The classmethod() decorator in Python is a built-in function that transforms a method into a class method. Unlike standard methods, class methods are not bound to an instance of the class, but rather to the class itself.
🌐
Mimo
mimo.org › glossary › python › class
Python Class: Syntax and Examples [Python Tutorial]
This instantiation process allows ... my_object: The variable name for the new instance of the class. Class methods define a class's behavior and allow instances of a class to perform specific actions....
🌐
W3Schools
w3schools.com › python › python_classes.asp
Python Classes
Almost everything in Python is an object, with its properties and methods. A Class is like an object constructor, or a "blueprint" for creating objects.