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
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)
🌐
PYnative
pynative.com › home › python › python object-oriented programming (oop) › python static method explained with examples
Python Static Method With Examples – PYnative
October 21, 2021 - Static methods are defined inside a class, and it is pretty similar to defining a regular function. To declare a static method, use this idiom: class C: @staticmethod def f(arg1, arg2, ...): ...Code language: Python (python)
Discussions

what is @staticmethod for?
The difference is only apparent when accessing the method through an instance of A, i.e. A().f(1, 2). f, being a static method, would behave exactly the same as when accessing it through the class. g, being a regular instance method, would automatically be passed the instance as the argument for x. So A().g(1, 2) would result in a TypeError, as it'd receive a total of three arguments. There's a final type of method, class methods using the @classmethod decorator, that are automatically passed a reference to the class they're accessed through, whether that's through the class directly or via one of its instances: class A: @classmethod def h(cls, x, y): return x + y A.h(1, 2) # cls = A A().h(1, 2) # same thing That's useful if the method call happens on a subclass of A, since the argument passed to h would be that subclass. To be honest, in most situations something should either be a class method, an instance method, or not a method, at all. In my experience, there's very few reasons to have static methods. More on reddit.com
🌐 r/learnpython
25
22
April 28, 2024
CLASS & STATIC METHODS
Classes for Beginners A lot of beginners struggle to get their heads around classes, but they are pretty much fundamental to object orientated programming. I usually describe them as the programming equal of moulds used in factories as a template for making lots of things that are identical. Imagine pouring molten iron into a mould to make a simple iron pot. You might produce a set of instructions to be sold with the pots that tell the owner how to cook using the pot, how to care for it, etc. The same instructions apply to every pot BUT what owners actually do is entirely up to them. Some might make soup, another person a stew, etc. In Python, a class defines the basics of a possible object and some methods that come with it. (Methods are like functions, but apply to things made using the class.) When we want create a Python object using a class, we call it 'creating an instance of a class'. If you have a class called Room, you would create instances like this: lounge = Room() kitchen = Room() hall = Room() As you typically want to store the main dimensions (height, length, width) of a room, whatever it is used for, it makes sense to define that when the instance is created. You would therefore have a method called __init__ that accepts height, length, width and when you create an instance of Room you would provide that information: lounge = Room(1300, 4000, 2000) The __init__ method is called automatically when you create an instance. It is short for initialise (intialize). You can reference the information using lounge.height and so on. These are attributes of the lounge instance. I provided the measurements in mm but you could include a method (function inside a class) that converts between mm and ft. Thus, I could say something like lounge.height_in_ft(). Methods in classes are usually defined with a first parameter of self: def __init__(self, height, length, width): # code for __init__ def height_in_ft(self): # code to return height The self is a shorthand way of referring to an instance. When you use lounge.height_in_ft() the method knows that any reference to self means the lounge instance, so self.height means lounge.height but you don't have to write the code for each individual instance. Thus kitchen.height_in_ft() and bathroom.height_in_ft() use the same method, but you don't have to pass the height of the instance as the method can reference it using self.height EXAMPLE Room class The code shown as the end of this post will generate the following output: Lounge 1300 4000 4000 Snug 1300 2500 2500 Lounge length in feet: 4.26509187 Snug wall area: 11700000 in sq.mm., 125.94 in sq.ft. Note that a method definition that is preceded by the command, @staticmethod (a decorator) is really just a function that does not include the self reference to the calling instance. It is included in a class definition for convenience and can be called by reference to the class or the instance: Room.mm_to_ft(mm) lounge.mm_to_ft(mm) Here's the code for the full programme: class Room(): def __init__(self, name, height, length, width): self.name = name self.height = height self.length = length self.width = width @staticmethod def mm_to_ft(mm): return mm * 0.0032808399 @staticmethod def sqmm_to_sqft(sqmm): return sqmm * 1.07639e-5 def height_in_ft(self): return Room.mm_to_ft(self.height) def width_in_ft(self): return Room.mm_to_ft(self.width) def length_in_ft(self): return Room.mm_to_ft(self.length) def wall_area(self): return self.length * 2 * self.height + self.width * 2 * self.height lounge = Room('Lounge', 1300, 4000, 2000) snug = Room('Snug', 1300, 2500, 2000) print(lounge.name, lounge.height, lounge.length, lounge.length) print(snug.name, snug.height, snug.length, snug.length) print(lounge.name, 'length in feet:', lounge.height_in_ft()) print(f'{snug.name} wall area: {snug.wall_area()} in sq.mm., ' + \ f'{snug.sqmm_to_sqft(snug.wall_area()):.2f} in sq.ft.') Another useful decorator is @property, which allows you to refer to a method as if it is an attribute. Not used in the example, but if I put that before the height_in_ft methods you could say, for example, lounge.height_in_ft instead of lounge.height_in_ft(). One can write classes that are based on other classes. These child classes inherit all of the characteristics of the parent (or super) class but any attribute or method can be overridden to use alternatives that apply only to the child (and its children). Such child classes might have additional methods, alternative __init__ methods, different default output when referenced in a print statement, and so on. The example code code does not demonstrate this feature. More on reddit.com
🌐 r/learnpython
12
2
December 30, 2021
What is the equivalent of @classmethod in another language like C++ or Java?
If a static method in Java doesn't access static members, it is equivalent to a @staticmethod in Python. If it does, it is equivalent to a @classmethod in Python. Python distinguishes between static and class methods because functions that are part of a class do not carry a reference to their instance object (conventionally called self) or their class object (conventionally called cls). Static methods don't need to access class variables, so they're not implicitly passed any instance or class object when called, and their signature doesn't have cls as first argument. Class methods access class variables, so they need to be (implicitly) passed a reference to their class object, and so their signature has cls as first argument. In contrast, non-static Java methods have this (often used implicitly), and static Java methods have static members in their scope, so there is no need for the class method / static method distinction. More on reddit.com
🌐 r/Python
9
3
May 9, 2014
Python 3 fact: Unbound methods are no more
Tweets tell very little. Why is this significant? What makes this a Good Thing? More on reddit.com
🌐 r/Python
22
21
May 12, 2011
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-static-method
Python staticmethod: When and How to Use Static Methods | DigitalOcean
September 16, 2025 - This usually happens when a function defined like an instance method is called as if it were static, or vice‑versa. Example: def add_numbers(x, y) inside a class but called as obj.add_numbers(1, 2) causes Python to pass self automatically, becoming three arguments.
🌐
Python Tutorial
pythontutorial.net › home › python oop › python static methods
Python Static Methods Explained Clearly By Practical Examples
October 25, 2021 - f = TemperatureConverter.celsius_to_fahrenheit(35) print(TemperatureConverter.format(f, TemperatureConverter.FAHRENHEIT)) Code language: Python (python) Use static methods to define utility methods or group a logically related functions into a class.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-staticmethod
Python @staticmethod - GeeksforGeeks
January 20, 2026 - class ClassName: @staticmethod def method_name(parameters): method_body ... Example 1: This example checks whether a number is even using a static method.
🌐
Programiz
programiz.com › python-programming › methods › built-in › staticmethod
Python staticmethod()
Hence, in newer versions of Python, you can use the @staticmethod decorator. ... The staticmethod() returns a static method for a function passed as the parameter.
🌐
Python Reference
python-reference.readthedocs.io › en › latest › docs › functions › staticmethod.html
staticmethod — Python Reference (The Right Way) 0.1 documentation
There are very few situations where static-methods are necessary in Python. The @staticmethod form is a function decorator. Also see classmethod() for a variant that is useful for creating alternate class constructors. >>> class Foo: ... @staticmethod ... def bar(): ... print 'bar' ... >>> Foo.bar <function bar at 0x00DBC1B0> >>> Foo().bar <function bar at 0x00DBC1B0> >>> Foo.bar() bar >>> Foo().bar() Bar · >>> # this example uses obsolete no-decorator syntax >>> class Foo: ...
Find elsewhere
🌐
Real Python
realpython.com › instance-class-and-static-methods-demystified
Python's Instance, Class, and Static Methods Demystified – Real Python
March 17, 2025 - To get warmed up, you’ll write a small Python file called demo.py with a bare-bones Python class that contains stripped-down examples of all three method types: ... class DemoClass: def instance_method(self): return ("instance method called", self) @classmethod def class_method(cls): return ("class method called", cls) @staticmethod def static_method() return ("static method called",)
🌐
GeeksforGeeks
geeksforgeeks.org › python › class-method-vs-static-method-python
Class method vs Static method in Python - GeeksforGeeks
3 weeks ago - A utility function is a helper function that performs a task related to the class but does not depend on class-level or instance-level data. ... Example: This example defines a utility function inside a class to check whether a person is an adult.
🌐
Tech with Tim
techwithtim.net › tutorials › python-programming › classes-objects-in-python › static-and-class-methods
Python Tutorial - Static and Class Methods
Like static methods they cannot access any instance attributes. You can create a class method by using the "@classmethod" decorator. class myClass: count = 0 def __init__(self): self.x = x @classmethod def classMethod(cls): cls.count += 1 # The classMethod can access and modify class variables. It takes the class name as a required parameter · Please refer to the video for further explanation and more detailed examples.
🌐
Tutorialspoint
tutorialspoint.com › python › python_static_methods.htm
Python - Static Methods
The second way to create a static method is by using the Python @staticmethod decorator. When we use this decorator with a method it indicates to the Interpreter that the specified method is static. ... In the following example, we are creating a static method using the @staticmethod decorator.
🌐
Better Stack
betterstack.com › community › questions › static-methods-in-python
How to Create Static Methods in Python? | Better Stack Community
June 19, 2024 - You can call a static method using the class name, as shown with MyClass.static_method(). Static methods are often used for utility functions that are related to the class but do not depend on specific instance data.
🌐
Tutorial Teacher
tutorialsteacher.com › python › staticmethod-decorator
Python Static Method Decorator - @staticmethod
#calling static method Student.tostring() #'Student Class' Student().tostring() #'Student Class' std = Student() std.tostring() #'Student Class'
🌐
Python Basics
pythonbasics.org › home › python basics › python's static methods demystified
Python's Static Methods Demystified - pythonbasics.org
Static method can be called without creating an object or instance. Simply create the method and call it directly. This is in a sense orthogonal to object orie
🌐
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 - Key differences: 1. Class methods receive the class as the first argument (`cls`) 2. Static methods don’t receive any automatic arguments 3. Class methods can access and modify class state 4. Static methods can’t access class or instance state without explicitly passing them · Here’s a practical example showing when to use each type:
🌐
Hostman
hostman.com › tutorials › python static method
Python Static Methods: Explained with Examples
April 16, 2025 - In the example, the is_adult static method serves as an auxiliary tool—a helper function—accepting the age argument but without access to the age attribute of the Person class instance. Static methods improve code readability and make it possible to reuse it. They are also more convenient when compared to standard Python functions.
Price   $
Address   1999 Harrison St 1800 9079, 94612, Oakland
🌐
StrataScratch
stratascratch.com › blog › how-to-define-and-use-static-methods-in-python
How to Define and Use Static Methods in Python - StrataScratch
July 21, 2025 - A practical guide to defining and applying static methods in Python using Walmarts Black Friday dataset to segment customer spending.
🌐
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 - In object-oriented programming (OOP), Python provides various tools for managing functions and logic within a class. One is @staticmethod, a decorator that allows us to define standalone methods within a class. These methods do not require access to class or instance data or attributes, so they are independent.
🌐
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.