python 的装饰器:
可以理解为高阶函数里面的嵌套函数
def func1():
pass
def func2(func1):
pass
def func3(func1):
return func1
其中func2 和 func3 是高阶函数
嵌套函数:
函数嵌套定义:
def func1():
pass
def func2():
pass
func1就属于嵌套函数
装饰器:
def func1(a,b):
c =a+b
return c
如果想给func1增加其他功能,而不改变其源代码的方式;
l例如:给func1加入一条打印输出
第一步:
def func2(func):
def func3(*args,**kwargs):
print "此函数为求和"
func(*args,**kwargs)
return func3
第二步:
@func2
def func1(a,b):
c =a+b
return c
第三步:
func1(1,2)