gpt4 book ai didi

python - 为什么删除 except 中使用的变量

转载 作者:太空宇宙 更新时间:2023-11-03 13:00:05 25 4
gpt4 key购买 nike

<分区>

为什么删除了except语句中使用的变量?我的意思是:

x = 0

try:
x = 5/0
except ZeroDivisionError as x:
pass

print(x)

我收到 NameError: name 'x' is not defined 为什么会这样?它不能像使用 def 或理解一样工作吗?如果在封闭函数(或模块)中有一个与变量同名的变量,它只是被隐藏而不是被删除?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com