Passing of members of one class to another class: ================================================= class myClass: a = 12 b = 12.23 def __init__(self): self.p = 112 self.q = 121 def m1(self): print("sum = ",self.p + self.q) In the above class, the members are: a, b, __init__(), m1(), p and q # Passing member of one class to another class. class Employee: def __init__(self,ename, eid, esal): self.ename = ename self.eid = eid self.esal = esal def display(self): print("The Name of an Employee = ",self.ename) print("The Id of an Employee = ",self.eid) print("The Salary of an Employee = ",self.esal) class Test: # @staticmethod # def modify1(emp): # emp.esal = emp.esal + 25000 # emp.display() def modify(self,emp): emp.esal = emp.esal + 25000 emp.display() # Attribute Error # @classmethod # def modify2(cls,emp): # emp.eid = 1221 # emp.display() e = Employee("Ashok", 1122, 125000) e.display() # Test.modify1(e) # Test.modify2(e) t = Test() t.modify(e) ================================================== Inner Class: ============ Writing of one class inside the another class is called as "Inner class". class car: class engine: car in the market ==> capacity of car engine if the car object is existing then only: engine object can exist. Ex: class phonepe: class sendMoney: mobileNumber(): UPI(): account(): class checkBalance: balanceEnquiry(): class texting: sending(): receiving(): # Inner Class class Calculator: a = 1212 b = 2121 class arithmetic: def addition(self): self.a = 1122 self.b = 2211 result = self.a + self.b return result def product(self): prod = self.a * self.b return prod calci = Calculator() print("data1 = ",calci.a) print("data2 = ",calci.b) # accepting the inner class # syntax: # object-name = outer-class-object.innerclass() iobj = calci.arithmetic() print("The Sum = ",iobj.addition()) print("The Product = ",iobj.product()) ====================================================== Garbage Collection: =================== all the data of python program can be managed by memory manager in private heap stack. The developer should not responsible for handling of memory. Handling of memory: creating the memory for data and deleting/releasing the memory for the data. ==> class data should also be automatically handled by memory manager in the private heap stack. ==> garbage collection is an automatic system which can able to create the memory for the object which we create for class. and release the memory for those objects of the class. class myClass: data methods m1 = myClass() m2 = myClass() m1.data m1.methods # Garbage Collection import gc # is garbage collection automatic? #isenabled() ==> we can check whether the garbage collection is enabled or not # True/False print(gc.isenabled()) # is is possible to disable? # Yes # disable() ==> we can disable the garbage collection # gc.disable() gc.disable() print(gc.isenabled()) # is it possible to start? # Yes # enable() ==> we can start the garbage collection #Syntax: gc.enable() gc.enable() print(gc.isenabled()) ============================================= Destructor: =========== ==> pre-defined name for destructor is: __del__ ==> is a special method ==> before the destroying an object, the garbage collector always calls the destructor to perform the clean up activities of that object. ==> Once the destructor completed the functionality, then the garbage collector will destroy that object. ==> always define in the class only. import time class Test: def __init__(self): print("Object is Initializing....") def __del__(self): print("Fulfilling last wish and performing cleanup activities...") t1 = Test() t1 = None time.sleep(5) print("End of Apllication.") ========================================== # HOW TO FIND THE NUMBER OF REFERENCES OF AN OBJECT. # getrefcount(): # can give the number of references of the specified object # import sys # sys.getrefcount(object-name) import sys class Test: pass # is the keyword, that we can use in functions/methods/class when those blocks with no # implementation. t1 = Test() t2 = t1 t3 = t1 t4 = t1 print("The Number of references of the class 'Test' is = ",sys.getrefcount(t1))