当垃圾回收机制执行的时候才会被调用,del的时候就不会被调用。
class C:
def __init__(self):
print("调用__init__")
def print_method(self):
print("method")
def __del__(self):
print("调用__del__")
c = C()
c.print_method()
c.print_method()
调用__init__
method
method
调用__del__