元组参数:*[parameter],表示调用函数时可以给多个同类型的实参。
字典参数:**[parameter],表示调用函数时可以给多个类似字典的实参。
示例:
1 def info(name, *bonus, **fruits): 2 tmp = 0 3 print("hello, I am %s"%(name)) 4 for item in bonus: 5 tmp += item 6 print("%d times, %d money"%(len(bonus), tmp)) 7 print("I like fruit, ", end = "") 8 for k, v in fruits.items(): 9 print(k, v, "个 ", sep=" ", end="") 10 11 info("xddd", 2, 5, 10, 20, 30, 50, apple="x", orange=1, peach=2)
输出:
1 hello, I am xddd 2 6 times, 117 money 3 I like fruit, apple x 个 orange 1 个 peach 2 个
找到一份更详细的介绍资料:https://blog.csdn.net/cadi2011/article/details/84871401
原文:https://www.cnblogs.com/rita-jia/p/12269524.html