首页 > 其他 > 详细

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

时间:2016-12-08 11:36:40      阅读:165      评论:0      收藏:0      [点我收藏+]

#高阶函数应用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),改变函数的调用方式

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

原文:http://www.cnblogs.com/huangjinshan/p/6144223.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!