python装饰器

1、python装饰器装之高阶函数

示例:

高阶函数
 1 import  time
 2 def bar():
 3     time.sleep(3)
 4     print('in the bar')
 5 def test1(func):
 6     print(func)   #打印这个func的内存地址
 7     return  func  #把函数的返回值返回
 8 #test1(bar)  #把bar传给func 相当于func = bar,把上面的bar函数传进来
 9 print(test1(bar)) #打印一下才能看到它的返回值 调用test1函数,bar这个函数传进来了,bar传给func了, 然后func函数里打印(func) 就出来第一个内存地址 完了结束后返回test1(bar)
10 test1(bar)

 

posted @ 2019-01-07 18:09  章十慕珊·  阅读(108)  评论(0编辑  收藏  举报