Destructors
Destructors are called when an object gets destroyed. In Python, destructors are not needed as much needed in C++ because Python has a garbage collector that handles memory management automatically. The __del__() method is a known as a destructor method in Python. It is called when all references to the object have been deleted i.e when an object is garbage collected.
Example 1:
Employee created.
Destructor called, Employee deleted.
Example 2:
Calling Create_obj() function...
Making Object...
Employee created function end...
Destructor called
Program End...
Last updated