def Fun1():
x = 5
def Fun2():
x*=x
return x
return Fun2()
上面程序有问题,修改方法如下两种方案:
def Fun1():
x = [5]
def Fun2():
x[0] *= x[0]
return x[0]
return Fun2()
def Fun1():
x = 5
def Fun2():
nonlocal x
x*=x
return x
return Fun2()
python局部变量实例
最新推荐文章于 2023-06-19 10:49:55 发布