【发布时间】:2018-10-24 09:50:09
【问题描述】:
给定以下代码:
msg = "test"
try:
"a"[1]
except IndexError as msg:
print("Error happened")
print(msg)
有人可以解释为什么这会导致 Python 3 中出现以下输出吗?
Error happened
Traceback (most recent call last):
File "test.py", line 6, in <module>
print(msg)
NameError: name 'msg' is not defined
【问题讨论】:
标签: python python-3.x scoping