实现使用引用计数来确定何时应删除变量。
在变量超出范围后(如您的示例),如果没有剩余的引用,则将释放内存。
def a(): x = 5 # x is within scope while the function is being executed print xa()# x is now out of scope, has no references and can now be deleted
除了列表中的字典键和元素外,通常没有什么理由在Python中手动删除变量。
但是,正如对该问题的回答所述,使用del可以显示意图。



