搜索
您的当前位置:首页正文

Python的__del__魔法方法

来源:步旅网

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

因篇幅问题不能全部显示,请点此查看更多更全内容

Top