Yep, using the staticmethod decorator:

class MyClass(object):
    @staticmethod
    def the_static_method(x):
        print(x)

MyClass.the_static_method(2)  # outputs 2

Note that some code might use the old method of defining a static method, using staticmethod as a function rather than a decorator. This should only be used if you have to support ancient versions of Python (2.2 and 2.3):

class MyClass(object):
    def the_static_method(x):
        print(x)
    the_static_method = staticmethod(the_static_method)

MyClass.the_static_method(2)  # outputs 2

This is entirely identical to the first example (using @staticmethod), just not using the nice decorator syntax.

Finally, use staticmethod sparingly! There are very few situations where static-methods are necessary in Python, and I've seen them used many times where a separate "top-level" function would have been clearer.


The following is verbatim from the documentation::

A static method does not receive an implicit first argument. To declare a static method, use this idiom:

class C:
    @staticmethod
    def f(arg1, arg2, ...): ...

The @staticmethod form is a function decorator – see the description of function definitions in Function definitions for details.

It can be called either on the class (such as C.f()) or on an instance (such as C().f()). The instance is ignored except for its class.

Static methods in Python are similar to those found in Java or C++. For a more advanced concept, see classmethod().

For more information on static methods, consult the documentation on the standard type hierarchy in The standard type hierarchy.

New in version 2.2.

Changed in version 2.4: Function decorator syntax added.

Answer from dbr on Stack Overflow
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-static-method
Python staticmethod: When and How to Use Static Methods | DigitalOcean
September 16, 2025 - The default method type in Python classes. Receives the instance (self) as the first argument. Can access and modify both instance and class variables. Used for behavior that depends on the state of a specific object. ... Use static methods for helpers that are conceptually part of a class’s ...
🌐
Tutorialspoint
tutorialspoint.com › python › python_static_methods.htm
Python - Static Methods
class Employee: empCount = 0 def ... following result − ... The second way to create a static method is by using the Python @staticmethod decorator....
Top answer
1 of 12
2349

Yep, using the staticmethod decorator:

class MyClass(object):
    @staticmethod
    def the_static_method(x):
        print(x)

MyClass.the_static_method(2)  # outputs 2

Note that some code might use the old method of defining a static method, using staticmethod as a function rather than a decorator. This should only be used if you have to support ancient versions of Python (2.2 and 2.3):

class MyClass(object):
    def the_static_method(x):
        print(x)
    the_static_method = staticmethod(the_static_method)

MyClass.the_static_method(2)  # outputs 2

This is entirely identical to the first example (using @staticmethod), just not using the nice decorator syntax.

Finally, use staticmethod sparingly! There are very few situations where static-methods are necessary in Python, and I've seen them used many times where a separate "top-level" function would have been clearer.


The following is verbatim from the documentation::

A static method does not receive an implicit first argument. To declare a static method, use this idiom:

class C:
    @staticmethod
    def f(arg1, arg2, ...): ...

The @staticmethod form is a function decorator – see the description of function definitions in Function definitions for details.

It can be called either on the class (such as C.f()) or on an instance (such as C().f()). The instance is ignored except for its class.

Static methods in Python are similar to those found in Java or C++. For a more advanced concept, see classmethod().

For more information on static methods, consult the documentation on the standard type hierarchy in The standard type hierarchy.

New in version 2.2.

Changed in version 2.4: Function decorator syntax added.

2 of 12
261

I think that Steven is actually right. To answer the original question, then, in order to set up a class method, simply assume that the first argument is not going to be a calling instance, and then make sure that you only call the method from the class.

(Note that this answer refers to Python 3.x. In Python 2.x you'll get a TypeError for calling the method on the class itself.)

For example:

class Dog:
    count = 0 # this is a class variable
    dogs = [] # this is a class variable

    def __init__(self, name):
        self.name = name #self.name is an instance variable
        Dog.count += 1
        Dog.dogs.append(name)

    def bark(self, n): # this is an instance method
        print("{} says: {}".format(self.name, "woof! " * n))

    def rollCall(n): #this is implicitly a class method (see comments below)
        print("There are {} dogs.".format(Dog.count))
        if n >= len(Dog.dogs) or n < 0:
            print("They are:")
            for dog in Dog.dogs:
                print("  {}".format(dog))
        else:
            print("The dog indexed at {} is {}.".format(n, Dog.dogs[n]))

fido = Dog("Fido")
fido.bark(3)
Dog.rollCall(-1)
rex = Dog("Rex")
Dog.rollCall(0)

In this code, the "rollCall" method assumes that the first argument is not an instance (as it would be if it were called by an instance instead of a class). As long as "rollCall" is called from the class rather than an instance, the code will work fine. If we try to call "rollCall" from an instance, e.g.:

rex.rollCall(-1)

however, it would cause an exception to be raised because it would send two arguments: itself and -1, and "rollCall" is only defined to accept one argument.

Incidentally, rex.rollCall() would send the correct number of arguments, but would also cause an exception to be raised because now n would be representing a Dog instance (i.e., rex) when the function expects n to be numerical.

This is where the decoration comes in: If we precede the "rollCall" method with

@staticmethod

then, by explicitly stating that the method is static, we can even call it from an instance. Now,

rex.rollCall(-1)

would work. The insertion of @staticmethod before a method definition, then, stops an instance from sending itself as an argument.

You can verify this by trying the following code with and without the @staticmethod line commented out.

class Dog:
    count = 0 # this is a class variable
    dogs = [] # this is a class variable

    def __init__(self, name):
        self.name = name #self.name is an instance variable
        Dog.count += 1
        Dog.dogs.append(name)

    def bark(self, n): # this is an instance method
        print("{} says: {}".format(self.name, "woof! " * n))

    @staticmethod
    def rollCall(n):
        print("There are {} dogs.".format(Dog.count))
        if n >= len(Dog.dogs) or n < 0:
            print("They are:")
            for dog in Dog.dogs:
                print("  {}".format(dog))
        else:
            print("The dog indexed at {} is {}.".format(n, Dog.dogs[n]))


fido = Dog("Fido")
fido.bark(3)
Dog.rollCall(-1)
rex = Dog("Rex")
Dog.rollCall(0)
rex.rollCall(-1)
🌐
W3schools
w3schools.tech › tutorial › python › python_static_methods
Python - Static Methods - Object Oriented Programming - W3schools
By using the @staticmethod decorator or the staticmethod() function, you can easily define and call static methods in your Python classes.
🌐
Tutorial Teacher
tutorialsteacher.com › python › staticmethod-decorator
Python Static Method Decorator - @staticmethod
The static method cannot access the class attributes or the instance attributes. The static method can be called using ClassName.MethodName() and also using object.MethodName(). It can return an object of the class. The following example demonstrates how to define a static method in the class:
🌐
Programiz
programiz.com › python-programming › methods › built-in › staticmethod
Python staticmethod()
The staticmethod() built-in function returns a static method for a given function. In this tutorial, we will learn about Python staticmethod() and its use-case with the help of examples.
🌐
GeeksforGeeks
geeksforgeeks.org › class-method-vs-static-method-python
Class method vs Static method in Python - GeeksforGeeks
July 26, 2024 - In general, static methods know nothing about the class state. They are utility-type methods that take some parameters and work upon those parameters. On the other hand class methods must have class as a parameter.
🌐
Python Reference
python-reference.readthedocs.io › en › latest › docs › functions › staticmethod.html
staticmethod — Python Reference (The Right Way) 0.1 documentation
This means we can put a function inside a class but we can’t access the instance of that class (this is useful when your method does not use the instance). staticmethods can be used when the code that belongs to a class doesn’t use the object itself at all. Python doesn’t have to instantiate a bound method for each object we instantiate.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python-staticmethod
Python @staticmethod - GeeksforGeeks
November 21, 2019 - When function decorated with @staticmethod is called, we don’t pass an instance of the class to it as it is normally done with methods. It means that the function is put inside the class but it cannot access the instance of that class.
🌐
Real Python
realpython.com › ref › glossary › static-method
static method | Python Glossary – Real Python
In this example, .add() and .subtract() are static methods that perform addition and subtraction, respectively. You can call them directly on the Calculator class or on an instance of the class without affecting instance or class state. ... In this tutorial, you'll compare Python's instance methods, class methods, and static methods.
🌐
Python Basics
pythonbasics.org › home › python basics › python's static methods demystified
Python's Static Methods Demystified - pythonbasics.org
You can however do something else: call a method in a class without creating an object. Demonstration of static method below. Define a class with a method. Add the keyword @staticmethod above it to make it static. ... A class can contain both static and non-static methods. If you want to call ...
🌐
Medium
medium.com › @ryan_forrester_ › class-methods-vs-static-methods-in-python-a-clear-guide-47fcfd385e27
Class Methods vs Static Methods in Python: A Clear Guide | by ryan | Medium
November 4, 2024 - class Example: class_variable = "I'm shared across all instances" def __init__(self, instance_var): self.instance_var = instance_var @classmethod def class_method(cls): print(f"Class method accessing class variable: {cls.class_variable}") return cls("Created via class method") @staticmethod def static_method(): print("Static method can't access class or instance variables directly") return "Static result" def instance_method(self): print(f"Instance method accessing instance var: {self.instance_var}") # Using the methods example = Example("instance value") # Class method can access class state
Top answer
1 of 1
22

Have you already read this?

https://en.wikipedia.org/wiki/Method_(computer_programming)

Especially this?

https://en.wikipedia.org/wiki/Method_(computer_programming)#Static_methods

Explanation

In OOP you define classes that you later on instantiate. A class is nothing more than a blueprint: Once you instantiate objects from a class your object will follow exactly the blueprint of your class. That means: If you define a field named "abc" in your class you will later on have a field "abc" in your object. If you define a method "foo()" in your class, you will later on have a method "foo()" to be invoked on your object.

Please note that this "on your object" is essential: You always instantiate a class and then you can invoke the method. This is the "normal" way.

A static method is different. While a normal method always requires to have an instance (where you then can invoke this method at) a static method does not. A static method exists independently from your instances (that's why it is named "static"). So a static method is associated with your class definition itself and therefore is always there and therefore can be invoked only at your class itself. It is completely independent from all instances.

That's a static method.

Python's implementation is a bit ... well ... simple. In details there are deviations from this description above. But that does not make any difference: To be in line with OOP concepts you always should use methods exactly as described above.

Example

Let's give you an example:

class FooBar:

  def someMethod(self):
    print("abc")

This is a regular (instance) method. You use it like this:

myObj = FooBar()
myObj.someMethod()

If you have ...

myObjB = FooBar()
myObjB.someMethod()

... you have an additional instance and therefore invoking someMethod() on this second instance will be the invocation of a second someMethod() method - defined at the second object. This is because you instantiate objects before use so all instances follow the blueprint FooBar defined. All instances therefore receive some kind of copy of someMethod().

(In practice Python will use optimizations internally, so there actually is only one piece of code that implements your someMethod() in memory, but forget about this for now. To a programmer it appears as that every instance of a class will have a copy of the method someMethod(). And that's the level of abstraction that is relevant to us as this is the "surface" we work on. Deep within the implementation of a programming or script language things might be a bit different but this is not very relevant.)

Let's have a look at a static method:

class FooBar:

  @staticmethod
  def someStaticMethod():
    print("abc")

Such static methods can be invoked like this:

FooBar.someStaticMethod()

As you can see: No instance. You directly invoke this method in the context of the class itself. While regular methods work on the particular instance itself - they typically modify data within this instance itself - a class method does not. It could modify static (!) data, but typically it does not anyway.

Consider a static method a special case. It is rarely needed. What you typically want if you write code is not to implement a static method. Only in very specific situations it makes sense to implement a static method.

The self parameter

Please note that a standard "instance" method always must have self as a first argument. This is a python specific. In the real world Python will (of course!) store your method only once in memory, even if you instantiate thousands of objects of your class. Consider this an optimization. If you then invoke your method on one of your thousands of instances, always the same single piece of code is called. But for it to distinguish on which particular object the code of the method should work on your instance is passed to this internally stored piece of code as the very first argument. This is the self argument. It is some kind of implicit argument and always needed for regular (instance) methods. (Not: static methods - there you don't need an instance to invoke them).

As this argument is implicit and always needed most programming languages hide it to the programmer (and handle this internally - under the hood - in the correct way). It does not really make much sense to expose this special argument anyway.

Unfortunately Python does not follow this principle. Python does not hide this argument which is implicitly required. (Python's incorporation of OOP concepts is a bit ... simple.) Therefore you see self almost everywhere in methods. In your mind you can ignore it, but you need to write it explicitly if you define your own classes. (Which is something you should do in order to structure your programs in a good way.)

The static method __new__()

Python is quite special. While regular programming languages follow a strict and immutable concept of how to create instances of particular classes, Python is a bit different here. This behavior can be changed. This behavior is implemented in __new__(). So if you do this ...

myObj = FooBar()

... Python implicitly invokes FooBar.__new__() which in turn invokes a constructor-like (instance) method named __init__() that you could (!) define in your class (as an instance method) and then returns the fully initialized instance. This instance is then what is stored in myObj in this example her.

You could modify this behavior if you want. But this would requires a very very very particularly unusual use case. You will likely never have anything to do with __new__() itself in your entire work with Python. My advice: If you're somehow new to Python just ignore it.

🌐
Medium
medium.com › @rahman.poland.ce21 › what-is-static-method-in-python-explanation-examples-and-advantages-33e4b0916aac
What is the Static Method in Python? Explanation, Examples, and Advantages | by A. Rahman | Medium
January 11, 2025 - Static methods are defined using the @staticmethod decorator before the function declaration. Unlike instance methods, static methods do not accept unique parameters such as self (for instance) or cls (for classes).
🌐
TutorialsPoint
tutorialspoint.com › class-method-vs-static-method-in-python
Class method vs static method in Python
July 30, 2019 - Syntax for Static Method. class my_class: @staticmethod deffunction_name(arguments): #Function Body return value · The Static methods are used to do some utility tasks, and class methods are used for factory methods.
🌐
Python Tutorial
pythontutorial.net › home › python oop › python static methods
Python Static Methods Explained Clearly By Practical Examples
October 25, 2021 - In practice, you use static methods to define utility methods or group functions that have some logical relationships in a class. To define a static method, you use the @staticmethod decorator: class className: @staticmethod def static_method_name(param_list): passCode language: Python (python)
🌐
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.
🌐
Real Python
realpython.com › ref › builtin-functions › staticmethod
staticmethod() | Python’s Built-in Functions – Real Python
In this example, .as_currency() and .as_percent() are static methods that format numbers without needing access to any instance or class variables. This helps to logically group utility functions within the Formatter class. ... In this tutorial, you'll compare Python's instance methods, class methods, and static methods.
🌐
Tech with Tim
techwithtim.net › tutorials › python-programming › classes-objects-in-python › static-and-class-methods
Python Tutorial - Static and Class Methods
When we create a static method we must use something called a decorator. The decorator for a static method is "@staticmethod". class myClass: def __init__(self): self.x = x @staticmethod def staticMethod(): return "i am a static method" # Notice staticMethod does not require the self parameter
🌐
PhoenixNAP
phoenixnap.com › home › kb › devops and development › what is a static method in python
What Is a Static Method in Python | phoenixNAP KB
July 13, 2023 - Learn how to use and write static methods in Python. See what static methods are used for and how they compare to class methods.