What is the __del__ method and how to call it?
The __del__ is a finalizer. It is called when an object is garbage collected which happens at some point after all references to the object have been deleted.
class Employee(): def __init__(self, name='John Doe'): print('Hello ' + name) self.name = name def developer(self): print(self.name) def __del__(self): print('Good Bye ' + self.name) emp = Employee('Mark') print(emp) emp = 'Rocky' print(emp)
Sample output of above program.
Hello Mark <__main__.Employee object at 0x00000000012498D0> Good Bye Mark Rocky
2019-07-01T00:30:17+05:30
2019-07-01T00:30:17+05:30
Amit Arora
Amit Arora
Python Programming Tutorial
Python
Practical Solution