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 MyClass:
2 def method(self):
3 return 'instance method called', self
4
5 @classmethod
6 def classmethod(cls):
7 return 'class method called', cls
8
9 @staticmethod
10 def staticmethod():
11 return 'static method called'
12
1x.counter = 1
2while x.counter < 10:
3 x.counter = x.counter * 2
4print(x.counter)
5del x.counter
6
7
8#https://docs.python.org/3.8/tutorial/classes.html#class-objects