class method and static method in python code example
Example 1: static methods in python
class Calculator:
@staticmethod
def addNumbers(x, y):
return x + y
print('Product:', Calculator.addNumbers(15, 110))
Example 2: python call static method in class
class MyClass:
@staticmethod
def static_method(n: int) -> int:
return n
num = static_method.__func__(10)
mc = MyClass()
print(mc.num)
Example 3: static methods in python
class Calculator:
def addNumbers(x, y):
return x + y
Calculator.addNumbers = staticmethod(Calculator.addNumbers)
print('Product:', Calculator.addNumbers(15, 110))