Skip to content

static method

In Python, a static method is a method that belongs to a class but doesn’t operate on an instance or the class itself.

You define a static method using the @staticmethod decorator. Static methods don’t receive an implicit self or cls argument. This means they can’t access or modify instance attributes or class attributes. The Python runtime enforces this behavior by not passing the instance or class object as an argument.

You often use static methods for utility functions that logically belong to a class but don’t require access to any instance or class-level data. They help organize code by keeping related functionality within a class.

Example

Here’s an example of using static methods:

Language: Python Filename: calculations.py
class Calculator:
    @staticmethod
    def add(a, b):
        """Returns the sum of two numbers."""
        return a + b

    @staticmethod
    def subtract(a, b):
        """Returns the difference between two numbers."""
        return a - b


# Calling a static method on the class
print(Calculator.add(5, 7))  # Output: 12

# Calling a static method on an instance
calculator = Calculator()
print(calculator.subtract(5, 7))  # Output: -2

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. Since Python 3.10, the staticmethod descriptor is itself callable, so you can also call a static method from inside the class body.

To see what the decorator changes, toggle @staticmethod on .subtract() and switch between calling the method on the calculator instance and on the Calculator class:

Interactive diagram — enable JavaScript to view.

With the decorator, Python passes only 5 and 7, wherever you call the method. Without it, an instance call makes Python slip calculator in as the first argument, shown in violet. It lands in a, pushes 5 into b, and leaves 7 with no parameter, so you get a TypeError. A call on the class still works because nothing is passed implicitly.

Python classmethods, staticmethods, and instance methods

Tutorial

Python's Instance, Class, and Static Methods Demystified

Compare instance methods vs class methods vs static methods in Python, and learn when each one earns its place in your code.

intermediate python

For additional information on related topics, take a look at the following resources:

Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.


By Leodanis Pozo Ramos • Updated Oct. 20, 2026 • Reviewed by Martin Breuss