请看下面的代码和报错信息:
def run():
x = 1
def inner():
if x > 0:
x = 9
inner()
run()
# 报错信息如下:
UnboundLocalError: local variable 'x' referenced before assignment
又修改了一下,加上全局变量声明,代码和报错信息如下:
def run():
x = 1
def inner():
global x
if x > 0:
x = 9
inner()
run()
# 报错信息如下:
NameError: name 'x' is not defined
求问到底是哪里错了,谢谢!