<分区> 分区>
Possible Duplicate:
Modify the function variables frominner function in python
假设我有这个 python 代码
def f():
x=2
def y():
x+=3
y()
这引发了:
UnboundLocalError: local variable 'x' referenced before assignment
那么,如何从内部函数“修改”局部变量'x'?在内部函数中将 x 定义为全局变量也会引发错误。
