static class in python code example
Example 1: static class python
>>>class Calculator:
@staticmethod
def multiplyNums(x, y):
return x * y
>>>print('Product:', Calculator.multiplyNums(15, 110))
Product:1650
Example 2: static methods in python
class Calculator:
@staticmethod
def addNumbers(x, y):
return x + y
print('Product:', Calculator.addNumbers(15, 110))
Example 3: python class static variable
>>> class MyClass:
... i = 3
...
>>> MyClass.i
3
Example 4: static methods in python
class Calculator:
def addNumbers(x, y):
return x + y
Calculator.addNumbers = staticmethod(Calculator.addNumbers)
print('Product:', Calculator.addNumbers(15, 110))