TYPES OF METHODS: ================= ==> three types: 1) Instance Methods 2) Static Methods 3) Class Methods 1) Instance Methods: ===================== ==> a method with instance variables is called as "instance method". ==> Instance methods can define inside the class and can access within the same class using "self" keyword. ==> the normal method in class with instance variables is called as "Instance methods" ==> Instance method can access outside the class using "object reference". # Instance Methods class InstanceClass: def __init__(self,name,age): # name and age ==> parameters for constructor # parameters of method/function/constructor ==> local variables # by converting local variables into instance variables, we can access instance variables in the entire class of any method self.name = name self.age = age def met(self): print("The name = ",self.name) print("The age = ",self.age) # calling of instance method inside the class def met2(self): self.met() obj = InstanceClass("Jk",28) obj.met() obj.met2() ========================================== 2) Static Methods ================== ==> the methods with static variables are called as "static methods". ==> always specify with an annotation/decorator: @staticmethod ==> To access the static method, we can use either the class name or object reference Syntax: class-name.meth-name() obj-name.meth-name() # Static Method class staticClass: def __init__(self): self.a = 100 self.b = 200 staticClass.c = 300 staticClass.d = 400 def met1(self): self.result = self.a + self.b print("The Sum is = ",self.result) # is it possible to define the instance method with static variable? # def met2(self): # self.diff = staticClass.c - staticClass.d # print("The Difference is = ",self.diff) @staticmethod def met2(x,y): print("The Product is = ",x*y) @staticmethod def met3(x,y): print("The Sum is = ",x+y) # calling of static method using instance method def met4(self): staticClass.met2(10,20) # calling of static method using another static method @staticmethod def met5(): staticClass.met3(500,600) obj = staticClass() obj.met1() # calling static method using the class name staticClass.met2(100,200) # calling the static method using object reference obj.met3(200,300) obj.met4() staticClass.met5()