Python中*和**的使用
来源:互联网 发布:html 炫酷展示页源码 编辑:程序博客网 时间:2024/06/06 01:20
当函数参数使用:
*args 当我们不知道要有多少个参数传给函数,或者我们想把一个列表或者tuple存起来以后传给函数。
**kwargs当我们不知道有多少个关键字参数要传给函数,或者我们想把字典存起来。
def fun(*args): print(args)def fun1(**kwargs): print(kwargs)if __name__ == '__main__': fun(2, 'laowang', True, [1,2,3]) print("============================") fun1(name='laowang',age=18,gender=True)
用于解包:
*用于解包元组:(开头,中间,末尾)
*用于解包列表:
使用 * 解压列表和元组类似
*用于解包字典:
字典使用**解包后当做函数的参数进行传递时,相当于给函数传递了关键字参数。
阅读全文
0 0
- Python中*和**的使用
- python中eval和exec的使用
- python中decode和encode的使用
- python中easy_install的安装和使用
- python中pip的使用和安装
- python中strip和split的使用
- python中startswith和endswith的使用
- Python中变量的命名和使用
- Python中strip和split的使用
- Python 中 and 和 or 的使用
- python中MySQLdb的execute和executemany的使用
- python中MySQLdb的execute和executemany的使用
- Python中ubuntu下的mongodb的安装和使用
- python中关于__file__ 和 sys.argv[0]的使用
- Python中__init__(),__getitem__()和__setitem__()的使用实例
- python中自定义包的导入和使用
- python中str.find和 in list的区别使用
- 我的python中matplotlib和seaborn使用记录
- 设计模式的应用场景(18)--命令模式
- 红黑树和二叉树
- centos6.5 网卡/etc/sysconfig/network: No such file or directory
- 如何使用RestTemplate访问restful服务
- JavaSE 循环结构
- Python中*和**的使用
- Pat(A) 1084. Broken Keyboard (20)
- JSON.parse问题(转)
- Atitit.每周计划日程表 流程表 v9 r829.docx
- Atitit 常见每日流程日程日常工作.docx v8 verampmimp 签到amy 天气情况检查amy 晨会,每天或者隔天am 每日计划(项目计划,日计划等。am
- 【LeetCode】645. Set Mismatch
- Struts2工作原理与Struts2工作流程
- ubuntu 配置java环境变量 修改/etc/environment 导致,登录界面进不去了
- Atitit.月度计划日程表 每月流程表v5