Python | local variable 'xxxx' referenced before assignment
程序员文章站
2022-04-29 20:58:26
函数func_in的局部变量num未定义而引发的错误: local variable 'num' referenced before assignment 函数func_in即使定义在函数func中,但它的变量仍然是局部变量,与函数func的参数num不相关。 ......
>>> def func(num):
... def func_in():
... num += 1
... print(num)
... return func_in
...
>>> fun = func(10)
>>> fun
<function func.<locals>.func_in at 0x1034410d0>
>>> fun()
traceback (most recent call last):
file "<stdin>", line 1, in <module>
file "<stdin>", line 3, in func_in
unboundlocalerror: local variable 'num' referenced before assignment
函数func_in的局部变量num未定义而引发的错误: local variable 'num' referenced before assignment
函数func_in即使定义在函数func中,但它的变量仍然是局部变量,与函数func的参数num不相关。
上一篇: Java集合---面试题
下一篇: python 字典所有操作