global:在局部声明变量是全局变量

x=1 def func(): global x x=2 func() print(x)
nonlocal:在局部声明变量是外层函数的变量

x=333 def f1(): x=222 def f2(): x=111 def f3(): nonlocal x x=0 f3() print('f2内部的x: ',x) f2() print('这是f1内部的x: ',x) f1() print(x)
有参装饰器:

def outter2(xxx,yyy): def outter(func): def wrapper(*args,**kwargs): res=func(*args,**kwargs) print(xxx) print(yyy) return res return wrapper return outter