python 传参中的*和**

https://www.cnblogs.com/moonbaby/p/12202208.html

 

def show_1(**kargs):
for item in kargs.items():
print(item)
user_dict = {'k1':123,'k2':456}

show_1(**user_dict) #kargs=user_dict
show_1(k1=123,k2=456,k3=789) #kargs=dict(k1=123,k2=456,k3=789)


def show_2(*args):
for item in args:
print(item)
user_list = ['rain','cloud','sun']

show_2(*user_list) #args=user_list
show_2('rain','cloud') #args=['rain','cloud']
show_2(user_list) #args=[user_list]

posted @ 2020-08-16 12:04  峡谷恶霸  阅读(168)  评论(0编辑  收藏  举报