python中,解包的作用和用法
文章目录
*对元组、列表解包
lis=(1,2,3)
def fun(*args):
print(args)
# lis解包后传入
fun(*lis)
# 输出(1,2,3)
# 不对lis解包直接传入
fun(lis)
# 输出((1,2,3),)
**对字典解包
传参时不解包会报错
dic = {"name": "Jack", "age": 27}
def func(**kwargs):
print(kwargs)
func(**dic)
# >> {'name': 'Jack', 'age': 27}
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论