INSTANCE METHODS: ================ Setter and Getter methods: ========================== to set instance variables and to get instance variables ==> setter and getter methods. Setter methods: ============== ==> use to set the instance variables ==> also called as "mutator methods" Syntax: def setVariable(self, variable): self.variable = value Getter Methods: =============== ==> use to get the instance variables ==> also called as "accessor methods" Syntax: def getVariable(self): return self.variable # Setter and Getter methods class Student: def setName(self,name): self.name = name def getName(self): return self.name def setMarks(self,marks): self.marks = marks def getMarks(self): return self.marks n = int(input("Enter number of students:")) for i in range(n): s = Student() name = input("Enter the student name:") s.setName(name) marks = int(input("Enter marks of the student:")) s.setMarks(marks) print("Hi,",s.getName()) print("Your Marks are:",s.getMarks()) ==================================================== Class Methods: ============== ==> the methods with only class variables (static variables) called as "class methods". @classmethod ==> class methods are always can call with "class name" or "object reference". # Class Methods class Animal: legs = 4 # static variable def m1(self): print("This is the Animal class.") @classmethod def walk(cls,name): print("{} walks with {} legs".format(name,cls.legs)) Animal.walk("Dog") am = Animal() am.walk("Cow") ========================================================= Static Methods: =============== ==> are called as "general utility methods" ==> inside the static methods, we won't include, class variables and instance variables.\ the variables with "self" and with "cls" were not in static method. ==> static method, not required "self" or "cls" as parameter in the definition. ==> annotation: @staticmethod ==> calling of static method: use: class name or object reference # static methods class Calculator: @staticmethod def add(x,y): print("The Sum = ",x+y) @staticmethod def multy(x,y): print("The Product = ",x*y) Calculator.add(100,200) cl = Calculator() cl.multy(23,27) ====================================== Passing of members of one class to another class: ================================================= cls1: mem1 mem2 cls2: mem2 # Passing the members of one class to another class. class Employee: def __init__(self,eno,ename,esal): self.eno = eno self.ename = ename self.esal = esal def display(self): print("The Id of the employee = ",self.eno) print("Name of the employee = ",self.ename) print("Salary of the Employee = ",self.esal) class Test: def modify(emp): emp.esal = emp.esal + 100000 emp.display() e = Employee(101,"Radhika",120000) e.display() Test.modify(e) ==================================== Inner Classes: ============== # Inner class class Outer: def __init__(self): print("Outer class Object Creation.") class Inner: def __init__(self): print("Inner class Object creation.") def m1(self): print("This is inner class method.") o = Outer() i = o.Inner() i.m1()