1. del 函数删除引用,并非对象 (以下代码是直接运行在Ipython console下)
#spyder: example 1 xx = [1,2,3] #赋值 xx #输出xx Out[2]: [1, 2, 3] del xx #删除引用,但未删除对象 xx #输出xx,报错 Traceback (most recent call last): File "<ipython-input-4-ce3af7760f12>", line 1, in <module> xx NameError: name 'xx' is not defined
#spyder: example 2 xx = [1,2,3] yy = xx xx Out[7]: [1, 2, 3] yy Out[8]: [1, 2, 3] del xx xx #输出xx报错 Traceback (most recent call last): File "<ipython-input-10-ce3af7760f12>", line 1, in <module> xx NameError: name 'xx' is not defined yy #输出yy Out[11]: [1, 2, 3] # 参考:https://www.cnblogs.com/xisheng/p/7340514.html