在阅读python代码的时候经常可以看到*keys和 **kwargs一直弄不明白现在明白了
参数中传入元组,args表示成一个元组
def param_tuple(*args):
print(args)
for value in args:
print(value)
print(enumerate(args))
for key,value in enumerate(args):
print("{0}->{1}".format(key,value))
param_tuple(1,2,43)
'''
(1, 2, 43)
1
2
43
0->1
1->2
2->43
'''
参数中传入元组,args表示成一个字典
def param_dic(**kwargs):
print(type(kwargs))
for name,age in kwargs.items():
print("{0}==>{1}".format(name,age))
param_dic(name="小明",age=20)
'''
(1, 2, 43)
1
2
43
0->1
1->2
2->43
'''
函数的参数中混用tuple和dic
def param_tuple_dic(*args,**kwargs):
print(type(args))
print(type(kwargs))
for value in args:
print(value)
for key ,value in kwargs.items():
print("{0}==>{1}".format(key,value))
param_tuple_dic("1","2","3",name="小明",age="10")
'''
1
2
3
name==>小明
age==>10
'''