@staticmethod

Represents a function as a static method.

Parameters

  • function: Function to be represented as a static method. Can be used as a decorator. Unlike regular methods or @classmethod, static methods do not receive the first argument implicitly. Static methods in Python are similar to those in C++ or Java.

Return Value

  • @staticmethod returns a static method for the function passed as a parameter.

Examples

To declare a static method, use @staticmethod as a decorator:

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

It can be called both through the class — C.f() — and through an instance — C().f(). Instance data is ignored, and only class data is considered.