关于Python中的*args和**kwargs
2016-03-25 13:37
531 查看
*args:所有参数的数组。
**kwargs:是当你传入key=value是存储的字典。
例如:
*args的使用
运行结果是:15
**kwargs的使用
运行结果:{'a': 4, 'b': 5}
**kwargs:是当你传入key=value是存储的字典。
例如:
*args的使用
def calc_sum(*args): ax = 0 for n in args: ax = ax + n return ax print(calc_sum(6,5,4))
运行结果是:15
**kwargs的使用
def test(**kwargs): print(kwargs) test(a=4,b=5)
运行结果:{'a': 4, 'b': 5}
相关文章推荐
- python 查找相应图片数据路径并调用exe程序
- Python collections.defaultdict()
- Python的禅,“提姆彼得斯”说的非常有道理道出了这门编程语言的真谛!
- Python学习笔记(三)Python的list和tuple
- python 静态成员变量
- python函数——编码问题——str与Unicode的区别
- 01python初识—编辑器&版本&变量知识
- Python学习笔记(四)Python函数的参数
- Python关键字总结
- 通过抓包获取跳转url并通过dnspython模块查询监控服务是否正常
- Python学习:Flask框架和jinja2模板
- bat调用python命令
- numpy.zeros(shape, dtype=float, order='C')
- numpy.ones(shape, dtype=None, order='C')
- Python 正则表达式的剖析
- python3安装Fabric模块
- python glob使用
- leetcode @python 120. Triangle
- 重装python idle打不开解决方案
- leetcode @python 119. Pascal's Triangle II