Python @staticmethod

Python @staticmethod decorator is used to transform a method into a static method.

In this tutorial, we will learn about the syntax of Python staticmethod() function, and learn how to use this function with the help of examples.


The syntax to use @staticmethod decorator to define a function f as static method in class A is

class A:
    def f(arg1, arg2, ...): ...

Please note that a static method does not receive an implicit first argument.



In this example, we define a class A, with f as static method.

Python Program

class A:
    def f():
        print('Hello World')

Try Online


Hello World

A static method does not require a class instance. We can just use the class name to call the static method.


In this Python Tutorial, we have learnt the syntax of Python staticmethod() builtin function, and also learned how to use this function, with the help of Python example programs.