How to Use staticmethod() Function in PythonPython Basics


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.

© 2024 Learnwithgpt.org, all rights reserved. Privacy Policy | Contact Us