装饰器带参数:
import time def timer(f): def inner(*args,**kwargs): start_time = time.time() res = f(*args,**kwargs) # 被装饰的函数 end_time = time.time() print(end_time - start_time) return res return inner @timer def func(a,b): # 传参 time.sleep(0.1) print("11111111",a,b) return 123456 @timer def func1(a,b): # 传参 time.sleep(0.1) print("11111111",a,b) return 123456 res = func(1,2) # inner res1 = func1(1,b=2) # inner print(res)