# 高阶函数 # 函数的参数是一个函数 # 函数的返回值是一个函数 # 函数作为参数 # import time # def foo(l): # for i in l: # print('詹姆斯,你好啊=======%s', i) # # # def test(func): # start_time = time.time() # func # stop_time = time.time() # print('函数耗时========%s' %(stop_time - start_time)) # # # test(foo(range(1000))) # def father(name): # def team(): # print('詹姆斯现在在%s队' %name) # def team2(): # name = '骑士' # print('詹姆斯原来在%s队' % name) # # team2() # # team() # father('湖人') import time def timer(func): def warper(): print(func) func() return warper # @timer 相当于 test = timer(test) 装饰器(不带返回值) @timer def test(): time.sleep(3) print('函数执行完毕') # res = timer(test) # res() # @timer 相当于 test = timer(test) # test = timer(test) test()
Python学习笔记------高阶函数以及不带返回值的装饰器
最新推荐文章于 2024-09-13 11:16:41 发布