>>> 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
Error local variables func_in caused by the undefined num: local variable 'num' referenced before Assignment
Even func_in function is defined in the function func, but it's still a variable is a local variable, not related to the parameters of function func num.