del什么时候在python中有用?我真的想不出为什么python需要del关键字(而且大多数语言似乎没有类似的关键字)。例如,与其删除变量,不如只分配None敬它。当从字典中删除时,del方法可以添加。有什么理由del在python中,还是Python垃圾前收集时代的遗迹?
3 回答

暮色呼如
TA贡献1853条经验 获得超9个赞
del list_item[4]del dictionary["alpha"]
del
del foo
foo = None
del foo
foo = None
foo = None
del foo

繁星淼淼
TA贡献1775条经验 获得超11个赞
del
删除名称将从本地或全局命名空间中删除该名称的绑定。
None

慕斯709654
TA贡献1840条经验 获得超5个赞
del
sys.exc_info()
try: do_evil()except: exc_type, exc_value, tb = sys.exc_info() if something(exc_value): raise
tb
try: do_evil()except: exc_type, exc_value, tb = sys.exc_info() del tb if something(exc_value): raise
sys.exc_info()
exc_type, exc_value = sys.exc_info()[:2]
添加回答
举报
0/150
提交
取消