一、什么是装饰器 Decorator 1.Python中一切皆对象,函数也可以当做参数传递 2.装饰器是接受函数作为参数,添加功能后返回一个新函数的函数(类) 3.Python中能过@使用装饰器 二、编写一个记录函数耗时的装饰器 import time def log_time(func): # 接受一个函数作为参数 def _log(*args, **kwargs): beg = time.time() res = func(*args, **kwargs) print(use time: { }'.format(time.time()-beg))