Post

Python staticmethod()

The staticmethod() is a built-in python function that returns a static method of a given function.

Python staticmethod()

The syntax of staticmethod() is:

1
2
staticmethod(function)

staticmethod() Parameters

The staticmethod() takes only one argument as parameters:

  • function - Name of the function that needs to be converted to a sciatic method.

Lets check an example of staticmethod() in python

Example 1: How to use the staticmethod() function in python ?

1
2
3
4
5
6
7
8
9
10
class Mathematics:

    def addNumbers(x, y):
        return x + y

# create addNumbers static method
Mathematics.addNumbers = staticmethod(Mathematics.addNumbers)

print('The sum is:', Mathematics.addNumbers(5, 10))

Output:

1
2
The sum is: 15

What is a static method?

This post is licensed under CC BY 4.0 by the author.