当前位置:主页 > 软件编程 > Python代码 >

python 函数内部修改外部变量的方法

时间:2021-04-10 08:53:17 | 栏目:Python代码 | 点击:

如果内部修改外部变量需要nonlocal,global

def f1():
 print("in f1..")
 num=111
 def f2():
  nonlocal num
  num=222
  print(num)
 f2()
 print(num)
f1()

您可能感兴趣的文章:

相关文章