当删除对象时,python解释器也会默认调用**del()**方法。
class Washer():
def __init__(self):
self.width = 300
def __del__(self):
print('对象已经删除')
haier = Washer() #输出对象已经删除
class Washer():
def __init__(self,width,height):
self.width = width
self.height = height
def __del__(self):
print(f'{self}对象已经删除')
haier = Washer(10,20)
#<__main__.Washer object at 0x0000020D1B54B6C8>对象已经删除
# del haier
class Washer():
def __init__(self,width,height):
self.width = width
self.height = height
def __del__(self):
print(f'{self}对象已经删除')
haier = Washer(10,20)
#<__main__.Washer object at 0x0000020D1B54B6C8>对象已经删除
del haier