把函数当作参数传给高阶函数


#高阶函数应用1:把函数当作参数传给高阶函数

import time
def foo():
print('form the foo')
def tmmer(func):
start_time=time.time()
func()
stop_time=time.time()
print('函数%s 运行时间是%s' %(func,stop_time-start_time))
tmmer(foo)

#总结:我们确实为函数foo增加了foo运行时间的功能,但是foo原来的执行方式是foo(),现在我们需要
调用高阶函数timmer(foo),改变函数的调用方式
原文地址:https://www.cnblogs.com/huangjinshan/p/6144223.html