python 传参中的*和**

 1 def show_1(**kargs):
 2     for item in kargs.items():
 3         print(item)
 4 user_dict = {'k1':123,'k2':456}
 5 
 6 show_1(**user_dict)  #kargs=user_dict
 7 show_1(k1=123,k2=456,k3=789)  #kargs=dict(k1=123,k2=456,k3=789)
 8 
 9 
10 def show_2(*args):
11     for item in args:
12         print(item)
13 user_list = ['rain','cloud','sun']
14 
15 show_2(*user_list)  #args=user_list
16 show_2('rain','cloud')  #args=['rain','cloud']
17 show_2(user_list)  #args=[user_list]

猜你喜欢

转载自www.cnblogs.com/moonbaby/p/12202208.html