Methods: ======== methods with parameters: ======================== class MyPractice: def method1(self): print("Hi") def method2(self,a,b,c): print("a = ",a) print("b = ",b) print("c = ",c) mp = MyPractice() mp.method1() mp.method2(101,121,111) ========================================== method with return type ======================= class MyPractice: def method1(self): print("Hi") def method2(self,a,b,c): print("a = ",a) print("b = ",b) print("c = ",c) def method3(self,p,q,r,s): result = p+q+r+s return result mp = MyPractice() mp.method1() mp.method2(101,121,111) x = mp.method3(11,22,33,44) print(x) print(mp.method3(101,111,121,131)) ================================================== Types of Methods: ================= -> 3-types of methods: 1) Instance method 2) Static method class MyPractice: # instance method def instanceMethod(self): print("Hi") print("I am an Instance Method") print("I can accept a default keyword 'self' without any value.") # static method @staticmethod def staticMethod(a,b): # self keyword is not required for static method as a parameter print("Hello") print("This is static method") print(a,b) # instance methods can always access with objects of teh class only. # instance method can be differently implemented from object to object. mp = MyPractice() mp.instanceMethod() # MyPractice.instanceMethod() # static method can allow to access with either object or with the class name. # when a method want to share among multiple objects of the same class equally, we can define # the static methdd mp.staticMethod(100,200) MyPractice.staticMethod(100,200) 3) Class method