Python staticmethod() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Built-in type

Definition

In Python, @staticmethod marks a method that is just a plain function stored in a class: it does not receive self (the instance) or cls (the class). You can call it on the class or on an instance with exactly the arguments you pass.

Use it for helper functions that belong with a class logically but need no instance or class data, such as unit conversions or validation. If the helper needs the class, use classmethod; if it needs object data, use a normal method.

staticmethod is a built-in type (a class) that you call like a function: each call creates a new staticmethod object. Like every built-in, it lives in the builtins module and is always available without an import.

Syntax

Usually written as a decorator.

python
class MyClass:
    @staticmethod
    def helper(x, y):
        return x + y
CallWhat it does
MyClass.helper(1, 2)Called on the class.
obj.helper(1, 2)Also works; no self is passed.
staticmethod(func)The non-decorator form.
self.helper(x)Call it from other methods.

A module-level function is often just as good; choose a static method when the function clearly belongs to the class's namespace.

Library declarations
python
staticmethod(function, /)
# class staticmethod: usually used as @staticmethod

Parameters

ParameterDescription
functionRequired. A function; it will be called without any automatic first argument.

Return Value

Return ValueDescription
staticmethodA static method object to store in the class body.

Python Examples

Example 1 — Utility Functions Grouped in a Class

Call two static helpers on the class and on an instance.

python
class Units:
    @staticmethod
    def km_to_m(km):
        return km * 1000

    @staticmethod
    def is_valid_distance(value):
        return value >= 0


print(Units.km_to_m(2.5))
print(Units().km_to_m(3))
print(Units.is_valid_distance(-1))

How It Works

  1. No self. km_to_m takes only the number it needs.
  2. Call on the class. Units.km_to_m(2.5) needs no object.
  3. Or on an instance. Units().km_to_m(3) passes nothing extra.
  4. Grouped helpers. Related conversions live in one namespace.

Example 2 — Instance, Class, and Static Methods Together

See which first argument each kind of method receives.

python
class Pizza:
    size = "medium"

    def __init__(self, topping):
        self.topping = topping

    def describe(self):
        return self.size + " " + self.topping

    @classmethod
    def margherita(cls):
        return cls("cheese")

    @staticmethod
    def slices(people, per_person=2):
        return people * per_person


p = Pizza.margherita()
print(p.describe())
print(Pizza.slices(4), p.slices(3, per_person=3))

How It Works

  1. Instance method. describe(self) reads data from one pizza.
  2. Class method. margherita(cls) builds a new pizza through cls.
  3. Static method. slices() just computes from its arguments: 4 × 2 and 3 × 3.
  4. Pick by need. Choose the kind based on whether the method needs the object, the class, or neither.

Example 3 — A Private Helper and the staticmethod() Call

Share a text-cleaning helper between methods, then attach a function with staticmethod().

python
class Validator:
    @staticmethod
    def _clean(text):
        return text.strip().lower()

    def __init__(self, allowed):
        self.allowed = {self._clean(a) for a in allowed}

    def check(self, value):
        return self._clean(value) in self.allowed


v = Validator([" Yes", "NO "])
print(v.check("yes"), v.check("  no"), v.check("maybe"))


def shout(text):
    return text.upper()


Validator.shout = staticmethod(shout)
print(Validator.shout("ok"), v.shout("hi"))

How It Works

  1. Shared cleanup. Both __init__ and check call self._clean().
  2. Normalized matching. Spaces and case are removed, so " no" matches "NO ".
  3. Call form. staticmethod(shout) attaches a module function to the class.
  4. Still no self. v.shout("hi") passes only "hi" to the function.

Frequently Asked Questions

A function defined inside a class that receives no automatic self or cls argument.
For helpers that belong with the class but do not need instance or class data.
A classmethod receives the class as cls; a staticmethod receives nothing extra.
No. Pass the object explicitly if you need it, or use a normal method.
You wrote a method without self and forgot @staticmethod, so Python passed the instance as an extra argument.

Next: str()

Convert any value to text, or decode bytes.

str() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful