Thursday, 12 July 2018

Python Destructor

Cited from the book "Python How to Program"

A destructor executes when an object is destroyed (e.g., after no more references to the object exist). A class can define a special method called __del__ that executes when the last reference to an object is deleted or goes out of scope. The method itself does not actually destroy the object -- it performs termination housekeeping before the interpreter reclaims the object’s memory, so that memory may be reused. A destructor normally specifies no parameters other than self and returns None.



No comments:

Post a Comment