在内部函数中可以修改外部函数的局部变量的值,就要用到nonlocal(非局部变量)
>>> def fun1():
x = 10
def fun2():
nonlocal x
x *= x
return x
return fun2
>>> fun1()()
100
>>> def fun1():
x = 10
def fun2():
nonlocal x
x *= x
return x
return fun2
>>> fun1()()
100