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
热门推荐
1 狗狗技能训练
5 如何训练狗狗笑
6 狗狗训练排便
9 狗狗响片训练
10 如何训练狗狗不捡食
11 狗狗尿训练
12 怎么训练狗狗找东西
13 狗狗训练站立
14 狗狗训练飞盘
15 鞍山狗狗训练
16 怎样训练泰迪狗狗谢谢
17 狗狗外出训练
18 怎么训练金毛狗狗大小便