python 装饰器
装饰器:本质就是一个函数
装饰器 = 高阶函数+嵌套函数
高阶函数:将一个函数作为另一个函数的参数。
import time
def aaa():
time.sleep(3)
print("aaa")
def test1(canshu1):
starttime = time.time()
canshu1()
endtime = time.time()
print('程序运行的时间是{}'.format(endtime-starttime))
test1(aaa)
这里就可以在不修改函数aaa源代码的情况下给函数aaa添加一个打印该函数运行时间的功能

浙公网安备 33010602011771号