Python del命令的作用
示例
使用delv,从范围中删除变量名,使用或从集合中删除对象,或使用delv[item]或del[i:j]从属性中删除属性delv.name,或通过其他任何方式删除对对象的引用,都不会触发任何析构函数调用或释放任何内存本身。对象仅在其引用计数达到零时才会被破坏。
>>> import gc
>>> gc.disable() #禁用垃圾收集器
>>> class Track:
def __init__(self):
print("Initialized")
def __del__(self):
print("Destructed")
>>> def bar():
return Track()
>>> t = bar()
Initialized
>>> another_t = t #分配另一个参考
>>> print("...")
...
>>> del t #尚未销毁-another_t仍引用它
>>> del another_t #最终引用不见了,对象被破坏了
Destructed
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短