Python | local variable 'xxxx' referenced before assignment
Posted qiutenglong
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python | local variable 'xxxx' referenced before assignment相关的知识,希望对你有一定的参考价值。
>>> 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不相关。
以上是关于Python | local variable 'xxxx' referenced before assignment的主要内容,如果未能解决你的问题,请参考以下文章
Python报错:UnboundLocalError: local variable ‘xxx‘ referenced before assignment
Python报错:UnboundLocalError: local variable ‘xxx‘ referenced before assignment
python 错误--UnboundLocalError: local variable '**' referenced before assignment
python报错:UnboundLocalError: local variable ‘np‘ referenced before assignment
”local variable 'xxx' referenced before assignment“python函数中改变外部定义数值时报错
Python-local variable 'raw_password' referenced before assignment