您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

python何时删除变量?

python何时删除变量?

实现使用引用计数来确定何时应删除变量。

在变量超出范围后(如您的示例),如果没有剩余的引用,则将释放内存。

def a():
    x = 5 # x is within scope while the function is being executed
    print x

a()
# x is Now out of scope, has no references and can Now be deleted

除了列表中的字典键和元素外,通常没有什么理由在Python中手动删除变量。

但是,正如对该问题的回答所述,使用del可以显示意图。

python 2022/1/1 18:39:37 有261人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶