python中tuple * 和 dict **

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_29007291/article/details/84314171

偶然见到以下用法 *tuple**dict作为参数, 经过查询,才知道这是一种简要写法, 见下面的例子


*tuple

def foo(x, y):
    print(x, y)

>>t = (1, 2)
>>foo(*t)
1 2

**dict

def foo(x, y):
    print(x, y)

>>> d = {'x':1, 'y':2}
>>> foo(**d)
1 2

参考:https://stackoverflow.com/questions/21809112/what-does-tuple-and-dict-means-in-python

猜你喜欢

转载自blog.csdn.net/qq_29007291/article/details/84314171