标签:top print rom 就是 检测 lang 定义 code app
准备内容:*args, **kwargs
在形参中的作用:
*args把多余的参数汇总成元组的形式存起来
**kwargs把多余的参数汇总成字典的形式存起来
在实参中的作用:
*args,*后面的内容打散成位置实参
**kwargs,**后面的内容打散成关键字实参
形参是汇总,实参是打散
import time
def func(x,y,z):
print(‘%s %s %s‘ %(x,y,z)
def timer(func):
def wrapper():
start_time = time.time()
res = func()
stop_time = time.time()
pritn(‘run time is %s‘ %(stop_time - start_time))
return res
return wrapper
import time
def timer(func):
def wrapper(*args,**kwargs):
start_time = time.time()
res = func(*args,**kwargs)
stop_time = time.time()
print(‘run time is %s‘ %(stop_time - start.time)
return res
return wrapper
@timer
def insex():
pass
有参装饰器本质上就是在原来装饰器的基础上再包一层函数
from functools import wraps
def timer(func):
@wraps(func)
def wrapper(*args,**kwargs):
start_time = time.time()
res = func(*args,**kwargs)
stop_time = time.time()
print(‘run time is %s‘ %(stop_time - start_time)
return res
return wrapper
标签:top print rom 就是 检测 lang 定义 code app
原文地址:https://www.cnblogs.com/xiaoxuanworking/p/14353173.html