Python staticmethod() FunctionPython Functions

Difficulty Level:
Difficulty Level:

The staticmethod() function returns a static method for a given function.

Example

class temp:
    def add(x, y):
        return x + y

temp.add = staticmethod(temp.add)
print('The sum is:', temp.add(35, 15))

Output:

The sum is: 50

Syntax

staticmethod(function)

Parameters

Name Description
Function The function that needs to be converted to a static method.

Return Value

It returns a static method for a function passed as the parameter.

Advertisement

© 2021 Pythonexample.org, all rights reserved. Privacy Policy | Contact Us