The destructor method __del__ is run automatically when an instance's space is being reclaimed:
class Life: def __init__(self, name='unknown'): print('Hello ' + name) self.name = name # from w w w. j a va 2s . c o m def live(self): print(self.name) def __del__(self): print('Goodbye ' + self.name) brian = Life('Brian') brian.live() brian = 'loretta'