装饰器:本身就是个函数,用来给其他函数增加附加的功能
def log():
pass

def function():
pass
log()


def funciton2():
pass
log()

# 函数的调用
装饰器原则:
1.不能修改被装饰的函数的源代码
2.不能修改被装饰的函数的调用方式
3.装饰器对被装饰的函数是完全透明的

装饰器:
1.函数即变量
2.高阶函数
3.嵌套函数
4.高阶函数+嵌套函数

内存回收机制:
python解释器进行垃圾回收机制:计数机制
x=1
匿名函数会被立马回收

匿名函数
calc =lambda x :x*3
calc()


定义变量
调用变量

 

import time

def timer(func):
def deco():
start_time = time.time()
func()
stop_time = time.time()
ex_time = stop_time - start_time
print(ex_time)
return deco

@timer
def t1():
time.sleep(1)
print('in the test1')

t1()
posted on 2019-06-26 12:47  Yihan_07  阅读(227)  评论(0编辑  收藏  举报