1#To create a static method, just add "@staticmethod" before defining it.
2
3>>>class Calculator:
4 # create static method
5 @staticmethod
6 def multiplyNums(x, y):
7 return x * y
8
9>>>print('Product:', Calculator.multiplyNums(15, 110))
10Product:1650
1# Instance Method Example in Python
2class Student:
3
4 def __init__(self, a, b):
5 self.a = a
6 self.b = b
7
8 def avg(self):
9 return (self.a + self.b) / 2
10
11s1 = Student(10, 20)
12print( s1.avg() )
1class Example:
2 staticVariable = 5
3
4print(Example.staticVariable) # Prints '5'
5
6instance = Example()
7print(instance.staticVariable) # Prints '5'
8
9instance.staticVaraible = 6
10print(instance.staticVariabel) # Prints '6'
11print(Example.staticVariable) # Prints '5'
12
13Example.staticVariable = 7
14print(Example.staticVariable) # Prints '7'