python *

作者: 锦绣拾年 | 来源:发表于2020-02-16 17:59 被阅读0次

python *

https://www.cnblogs.com/xujiu/p/8352635.html

【Python—参数】*arg与**kwargs参数的用法

在python中,这两个是python中的可变参数,*arg表示任意多个无名参数,类型为tuple;(输入参数自动组成元组)

**kwargs表示关键字参数,为dict。 (x=2,y=3;自动组成{x:2,y:3}字典)

https://blog.csdn.net/liuweizj12/article/details/79893673

列表前面加星号作用是将列表解开成两个独立的参数,传入函数,

字典前面加两个星号,是将字典解开成独立的元素作为形参。

def add(a, b):
    return a+b
 
data = [4,3]
print add(*data)
#equals to print add(4, 3)
data = {'a' : 4, 'b' : 3}
print add(**data)
#equals to print add(4, 3)

相关文章

网友评论

      本文标题:python *

      本文链接:https://www.haomeiwen.com/subject/nkrmfhtx.html