class Test(object): def __del__(self): print("Object deleted") def func(self): print("Random function") obj = Test() obj.func() del obj obj.func()