It used to matter more back in Python 2, where the instance-ness of instance methods was enforced more strongly:

>>> class B:
...     def f(x):
...         print("x is", x)
...
>>> B.f(1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unbound method f() must be called with B instance as first argument (
got int instance instead)

You had to mark static methods with @staticmethod back then.

These days, @staticmethod still makes it clearer that the method is static, which helps with code readability and documentation generation, and it lets you call the method on instances without the system trying to bind self.

Answer from user2357112 on Stack Overflow
🌐
Tutorial Teacher
tutorialsteacher.com › python › staticmethod-decorator
Python Static Method Decorator - @staticmethod
The @staticmethod is a built-in decorator that defines a static method in the class in Python.
Discussions

Python decorator as a staticmethod - Stack Overflow
I'm happy to just remove the @staticmethod, I would just like to know why it works. Without that the staticmethod decorator, is ensure_black still a static method? 2011-06-20T14:09:01.823Z+00:00 ... @wkz: No, it's just a plain Python function defined inside the scope of the class TFord. More on stackoverflow.com
🌐 stackoverflow.com
Confused about decorators, classmethod and staticmethod
I recommend having a look at the Pythons class development YouTube lecture by Raymond Hettinger who is a Python core developer. The talk is old and is about Python 2 but can be easily adapted to Python 3. In essence most methods are instance methods and are designed to access instance data: class CustomClass(object): def __init__(x, y): self.x = x self.y = y def x_squared(self): return self.x ** 2 self essentially means "this instance" and so: this_instance = CustomClass(3, 4) When the method is called from the class, an instance needs to be supplied: CustomClass.x_squared(self=this_instance) The method can then work on the instance data. Normally self is provided positionally. When a method is called from an instance, the instance is implied: this_instance.x_squared() And therefore the instance data from this_instance will be used. The main use of a class method is an alternative constructor: class CustomClass(object): def __init__(x, y): self.x = x self.y = y @classmethod def from_inverse(cls, a, b): x = 1 / a y = 1 / b return CustomClass(x, y) This means a new CustomClass can be created using: this_instance = CustomClass(x=3, y=4) Or the alternative constructor: that_instance = CustomClass.from_inverse(a=1/3, b=1/3) Notice that the class method is called from the class and does not have an instance. The class method can be called from an instance although it is not common to do so: that_instance = this_instance.from_inverse(a=1/3, b=1/3) However all it does is determine the type of the class from the instance and invoke the class method and does not access instance data. Examples of this are in the datetime class (in the datetime module) which has from_isoformat, from_isocalendar, from_ordinal and from_timestamp which each act as alternative constructors for the datetime class from differing input formats. Notice most the alternative constructors have from in the method name. now is also an alternative constructor, constructing a datetime instance from the system clock. The final method, the static method is neither bound to a class or a method. It is far less commonly used. The static method is a regular function found in the namespace of a class and is only placed there for convenience. Notice that it neither has self (an instance) or cls (a class) as the first input argument and is therefore not bound to an instance or a class: class CustomClass(object): def __init__(x, y): self.x = x self.y = y @staticmethod def some_function(c, d): return c + d The video tutorial by Raymond Hettinger will give you a better understanding. More on reddit.com
🌐 r/learnpython
10
8
December 24, 2023
@staticmethod vs @classmethod vs functions outside of class in Python - Software Engineering Stack Exchange
I have some static functions in a Python class. The advantage to using the @staticmethod decorator is that it informs the reader that the method doesn't require any information from the class or More on softwareengineering.stackexchange.com
🌐 softwareengineering.stackexchange.com
I don't see the benefit of @staticmethod decorator
>>> f=Fruit() >>> f.some_func("hello") TypeError: some_func() takes 1 positional argument but 2 were given >>> f2 = Fruitas() >>> f2.algo_func("hello") hello So with the staticmethod decorator, it's still a static method even if it is called from an instance via self; it's less prone to misuse, and also instances can use it without having to know their own class name. More on reddit.com
🌐 r/learnpython
8
3
May 19, 2020
🌐
Python Reference
python-reference.readthedocs.io › en › latest › docs › functions › staticmethod.html
staticmethod — Python Reference (The Right Way) 0.1 documentation
Bound methods are objects too, and creating them has a cost. Having a static method avoids that. There are very few situations where static-methods are necessary in Python. The @staticmethod form is a function decorator.
🌐
IONOS
ionos.com › digital guide › websites › web development › python staticmethod()
Python staticmethod() tutorial - IONOS
December 3, 2024 - class Calculator: @staticmethod ... methods for cal­cu­lat­ing the square and square root of a number. We use the @staticmethod decorator to mark square() and sqroot() as static methods....
🌐
Sentry
sentry.io › sentry answers › python › difference between `@staticmethod` and `@classmethod` function decorators in python
Difference between `@staticmethod` and `@classmethod` function decorators in Python | Sentry
October 21, 2022 - class Greeter: def __init__(self, name): self.name = name @staticmethod def say_hello_static(name): # <-- no self parameter print(f"Hello {name}, how are you?") alice = Greeter("Alice") alice.say_hello_static("Bob") # will print "Hello Bob, how are you?" This can be useful when we have functionality that logically belongs in a given class, but does not do anything with the instance it’s called on. By contrast, the @classmethod decorator will make Python pass the class of the instance it’s called on as the first argument. By convention, the first parameter of a class method is called cls.
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-static-method
Python staticmethod: When and How to Use Static Methods | DigitalOcean
September 16, 2025 - Defined with @classmethod decorator. Receives the class (cls) as the first argument. Can access and modify class variables, and is often used for alternative constructors or methods that need to know about the class (including subclasses). ... The default method type in Python classes.
Top answer
1 of 4
48

This is not how staticmethod is supposed to be used. staticmethod objects are descriptors that return the wrapped object, so they only work when accessed as classname.staticmethodname. Example

class A(object):
    @staticmethod
    def f():
        pass
print A.f
print A.__dict__["f"]

prints

<function f at 0x8af45dc>
<staticmethod object at 0x8aa6a94>

Inside the scope of A, you would always get the latter object, which is not callable.

I'd strongly recommend to move the decorator to the module scope -- it does not seem to belong inside the class. If you want to keep it inside the class, don't make it a staticmethod, but rather simply del it at the end of the class body -- it's not meant to be used from outside the class in this case.

2 of 4
12

Python classes are created at runtime, after evaluating the contents of the class declaration. The class is evaluated by assigned all declared variables and functions to a special dictionary and using that dictionary to call type.__new__ (see customizing class creation).

So,

class A(B):
    c = 1

is equivalent to:

A = type.__new__("A", (B,), {"c": 1})

When you annotate a method with @staticmethod, there is some special magic that happens AFTER the class is created with type.__new__. Inside class declaration scope, the @staticmethod function is just an instance of a staticmethod object, which you can't call. The decorator probably should just be declared above the class definition in the same module OR in a separate "decorate" module (depends on how many decorators you have). In general decorators should be declared outside of a class. One notable exception is the property class (see properties). In your case having the decorator inside a class declaration might make sense if you had something like a color class:

class Color(object):

    def ___init__(self, color):
        self.color = color

     def ensure_same_color(f):
         ...

black = Color("black")

class TFord(object):
    def __init__(self, color):
        self.color = color

    @black.ensure_same_color
    def get():
        return 'Here is your shiny new T-Ford'
Find elsewhere
🌐
Desy
hasyweb.desy.de › services › computing › python › node61.html
The @staticmethod decorator
The decorator @staticmethod turns a function into a static method which does not depend of self. These kind of functions could also live in the module name space. The staticmethod decorator is used, if functions are somehow related to a class and should be stored there.
🌐
Reddit
reddit.com › r/learnpython › confused about decorators, classmethod and staticmethod
r/learnpython on Reddit: Confused about decorators, classmethod and staticmethod
December 24, 2023 -

Hi r/learnpython, I'm currently working through djangoforbeginners and encountered the usage of classmethod() as a decorator for testing using setUpTestData().

I'm really trying to get comfortable reading the docs, but I feel like the explanations are using other terms I don't really understand to explain it, and feel like it's just looping into each other without a dumbed down explanation.

From what I could gather reading the docs, decorators make the code look neater in a similar(?) sense that list comprehension make it easier to read? I also don't quite understand what classmethod and staticmethod does that's different to just defining your own function. What do they mean by staticmethod not receiving an "implicit argument" vs. classmethod which does?

Please help an absolute clean slate beginner here! TIA.

Top answer
1 of 5
9
I recommend having a look at the Pythons class development YouTube lecture by Raymond Hettinger who is a Python core developer. The talk is old and is about Python 2 but can be easily adapted to Python 3. In essence most methods are instance methods and are designed to access instance data: class CustomClass(object): def __init__(x, y): self.x = x self.y = y def x_squared(self): return self.x ** 2 self essentially means "this instance" and so: this_instance = CustomClass(3, 4) When the method is called from the class, an instance needs to be supplied: CustomClass.x_squared(self=this_instance) The method can then work on the instance data. Normally self is provided positionally. When a method is called from an instance, the instance is implied: this_instance.x_squared() And therefore the instance data from this_instance will be used. The main use of a class method is an alternative constructor: class CustomClass(object): def __init__(x, y): self.x = x self.y = y @classmethod def from_inverse(cls, a, b): x = 1 / a y = 1 / b return CustomClass(x, y) This means a new CustomClass can be created using: this_instance = CustomClass(x=3, y=4) Or the alternative constructor: that_instance = CustomClass.from_inverse(a=1/3, b=1/3) Notice that the class method is called from the class and does not have an instance. The class method can be called from an instance although it is not common to do so: that_instance = this_instance.from_inverse(a=1/3, b=1/3) However all it does is determine the type of the class from the instance and invoke the class method and does not access instance data. Examples of this are in the datetime class (in the datetime module) which has from_isoformat, from_isocalendar, from_ordinal and from_timestamp which each act as alternative constructors for the datetime class from differing input formats. Notice most the alternative constructors have from in the method name. now is also an alternative constructor, constructing a datetime instance from the system clock. The final method, the static method is neither bound to a class or a method. It is far less commonly used. The static method is a regular function found in the namespace of a class and is only placed there for convenience. Notice that it neither has self (an instance) or cls (a class) as the first input argument and is therefore not bound to an instance or a class: class CustomClass(object): def __init__(x, y): self.x = x self.y = y @staticmethod def some_function(c, d): return c + d The video tutorial by Raymond Hettinger will give you a better understanding.
2 of 5
2
Thank you everyone who have put so much thought into their responses. I'm sure all your explanations have been broken down into the simplest way possible, I think I'll need to spend more time experimenting with all your examples to get my head around. Thanks!
🌐
Stack Abuse
stackabuse.com › pythons-classmethod-and-staticmethod-explained
Python's @classmethod and @staticmethod Explained
November 21, 2021 - The decorator becomes even more useful when you realize its usefulness in sub-classes. Since the class object is given to you within the method, you can still use the same @classmethod for sub-classes as well. The @staticmethod decorator is similar to @classmethod in that it can be called from an uninstantiated class object, although in this case there is no cls parameter passed to its method.
Top answer
1 of 2
3

If your method calls a static method on the class, then it does require information on the class. You have a class method, not a static method. By declaring it @classmethod (and adding the cls parameter), you not only properly inform the reader, you allow polymorphism. An inheritor can reimplement the called static method and change behavior.

2 of 2
2

Python's static methods are intended for methods that are part of a class, and can be called as either a class method or an instance method: both Class.the_method() and self.the_method() would work. When the static method is called, it is not given an implicit first argument:

class Example:
  def instance_method_example(self, arguments):
    ...

  @classmethod
  def class_method_example(cls, arguments):
    ...

  @staticmethod
  def static_method_example(arguments):
    ...

If you merely want to create a helper function that is used within your class, do not use @staticmethod. Define a free function outside of the class. For example:

class Example:
  def some_method(self, argument):
    return _helper(argument, self.x)

def _helper(a, b):
  ...

The background of static methods in Python is the following: when you access an attribute of an object x.attribute or getattr(x, 'attribute'), then this name is looked up in the instance dict or the class dict. If an object is found in the class dict, it is checked whether that object is a “descriptor”: an object that describes how this attribute behaves, not an object that would be directly returned. Descriptors have dunder-methods like __get__, __set__, and __del__ that are invoked depending on whether the descriptor is accessed, assigned to, or deleted with the del operator.

Functions – the things you declare with def – are descriptors. By default, the __get__ descriptor binds the function to the instance argument (typically called self) and returns the bound function, so that it can be invoked as a method. But the various decorators change this behaviour:

  • a @classmethod def binds to the class object, not the instance
  • a @staticmethod def does not bind to any object and just returns the underlying function directly
  • a @property invokes the underlying function to retrieve a value

These differences are (partially) visible when looking at the repr() of the bound methods. With the first Example class:

  • instance_method_example
    • with class: Example.instance_method_example
      is <function Example.instance_method_example at 0x7f1dfdd6fd30>,
      the unbound function
    • with instance: <function Example.instance_method_example at 0x7f1dfdd6fd30>
      is <bound method Example.instance_method_example of <__main__.Example object at 0x7f1dfdddcb80>>,
      a method bound to the instance
  • class_method_example
    • with class: Example.class_method_example
      is <bound method Example.class_method_example of <class '__main__.Example'>>,
      a method bound to the class
    • with instance: Example().class_method_example
      is <bound method Example.class_method_example of <class '__main__.Example'>>,
      also a method bound to the class
  • static_method_example
    • with class: Example.static_method_example
      is <function Example.static_method_example at 0x7f1dfdd6fe50>,
      the unbound function
    • with instance: Example().static_method_example
      is <function Example.static_method_example at 0x7f1dfdd6fe50>,
      also the unbound function

As a table:

invoked on… no decorator @classmethod @staticmethod
… instance bound to instance bound to class unbound
… class unbound bound to class unbound
🌐
Real Python
realpython.com › ref › builtin-functions › staticmethod
staticmethod() | Python’s Built-in Functions – Real Python
The built-in staticmethod() function is a decorator that lets you transform a method into a static method. Static methods don’t receive an implicit first argument, meaning they don’t have access to the instance (self) or class (cls) objects.
🌐
Theodo
data-ai.theodo.com › blog
Under the hood of staticmethod: let’s recode this decorator!
@staticmethod is a class decorator, reimplementing __get__ and making it return a version of the decorated method that has not been bound to the object it belongs to. Hence, the decorated method does not have the implicit argument self.
🌐
Better Programming
betterprogramming.pub › how-to-use-the-magical-staticmethod-classmethod-and-property-decorators-in-python-e42dd74e51e7
How to Use the Magical @staticmethod, @classmethod, and @property Decorators in Python
August 25, 2023 - We will introduce three special decorators in Python, namely @staticmethod, @classmethod, and @propery which can make your code cleaner and more professional
🌐
EDUCBA
educba.com › home › software development › software development tutorials › python tutorial › python @staticmethod
Boosting Code Efficiency with @staticmethod in Python
May 13, 2024 - The @staticmethod decorator is essentially another built-in function that doesn’t require any parameters. You use it to define static methods, which do not take any parameters and cannot access or modify the class’s state.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
GitHub
gist.github.com › esoergel › 544c938d8ffdfcaba82a
Brief explanation and example of python's `staticmethod` decorator · GitHub
The @classmethod decorator gives you access to the uninstantiated class, but still has some coupling with the class itself. The @staticmethod decorator basically lets you define a normal function within the context of a class.
🌐
Medium
medium.com › data-science › python-decorators-in-oop-3189c526ead6
Python: Decorators in OOP. A guide on classmethods, staticmethods… | by Aniruddha Karajgi | TDS Archive | Medium
January 27, 2021 - To do this, we can simply add @staticmethod above the get_percent method. The property decorator provides methods for accessing (getter), modifying (setter), and deleting (deleter) the attributes of an object.
🌐
Hostman
hostman.com › tutorials › python static method
Python Static Methods: Explained with Examples
April 16, 2025 - In Python, static methods apply not only in classes but also in modules and packages. The @staticmethod decorator marks a function you define inside a class if it does not interact with instance-specific data.
Price   $
Address   1999 Harrison St 1800 9079, 94612, Oakland
🌐
Reddit
reddit.com › r/learnpython › i don't see the benefit of @staticmethod decorator
r/learnpython on Reddit: I don't see the benefit of @staticmethod decorator
May 19, 2020 -

Hello. I'm having a hard time wrapping my brain around what the staticmethod decorator does for me. From what I've read, it allows me to access the class method without instantiation.... got it. But it seems that I can do that anyway.

class Fruit:
    def some_func(some_text):
        print(some_text)

class Fruitas:
    @staticmethod
    def algo_func(algo_texto):
        print(algo_texto)

Fruit.some_func('hello, world')
Fruitas.algo_func('hola, mundo')

hello, world

hola, mundo

Why do people say that it offers access to the method without instantiation? Any insight is greatly appreciated.

Looked so far: python.org, pythonbasics.org, /learnpython 'staticmethod', various online tutorials, o'reilly python book.

Top answer
1 of 5
3
>>> f=Fruit() >>> f.some_func("hello") TypeError: some_func() takes 1 positional argument but 2 were given >>> f2 = Fruitas() >>> f2.algo_func("hello") hello So with the staticmethod decorator, it's still a static method even if it is called from an instance via self; it's less prone to misuse, and also instances can use it without having to know their own class name.
2 of 5
2
So I think there are two questions here: 1) what is the difference in your two examples, and 2) why does @staticmethod exist. So for 1): The difference is that the Fruit method does not work if you instantiate the class. You'll get a TypeError complaining about the wrong number of parameters, because for normal (non-static, non-class) methods, the first parameter is automatically and always the instance itself. With class methods it's the class, and with static methods it's not filled in. The reason this works in your code is basically a quick of how this is implemented internally. For 2): Honestly idk. It's basically a glorified namespace at that point. Personally I basically never use @staticmethod. Maybe there's some use for like utility functions that are commonly helpful in the same location as instances of that class but meh. I don't use it. I have noticed that some people, especially people that learned programming with Java, seem to be allergic to standalone functions. C++ programmers as well for some reason, which I don't get because c++ is just fine with standalone function, but I digress.