What is Static Method in Python
Static methods are mthods that are bound to a class rather than its object. They do not require a class instance creation, therefore they are independent on the state of the object.
staticmethod() is a built-in function in Python which returns a static method for a given function.
class calculator: def add(x, y): return x + y calculator.add = staticmethod(calculator.add) print("Sum = ", calculator.add(2, 3))
Sum = 5
Static method knows nothing about the class and it just deals with the parameters.
Please login to comment
View all comments