赞
踩
函数的可变 参数主要有2中体现
1 * 可以一次传递多个参数
2 ** 可以传递字典
- # 可变参数 *
- def add(*num):
- count = 0
- for i in num:
- count = count + i
- return count
-
-
- # 可变参数**
- def getResult(**result):
- for i in result.items():
- print(i)
-
-
- if __name__ == "__main__":
- number = (1, 2, 3, 4, 5, 6)
- print(add(*number))
- infor = {"小明": "15", "小李": "16"}
- getResult(**infor)

打印结果如下.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。