直接上Python代码
# 如果不知道需要传多少个参数,可以用 *args
def func(*args):
print(args)
print(type(args))
print("*******")
func(1,2,3)
func([1,2,4])
func([1,2], "erer")
##############################
# 要想指定参数对应的数值,可以用 **kwargs
def func1(**kwargs):
print(kwargs)
print(type(kwargs))
print("**********")
func1(v1=123, v2=456)
func1(k1="were")
func1()
结果如下
(1, 2, 3)
<class 'tuple'>
*******
([1, 2, 4],)
<class 'tuple'>
*******
([1, 2], 'erer')
<class 'tuple'>
*******
{'v1': 123, 'v2': 456}
<class 'dict'>
**********
{'k1': 'were'}
<class 'dict'>
**********
{}
<class 'dict'>
**********
点个赞呗~