For beginners, see *args and **kargs on the head of the big, in the end what they are useful, how to use? This article will uncover the mysteries of variable parameters for you.
1.*args essence is the parameter passed into the function, stored in the variable args of the tuple type
def Fun_var_args (farg, *args): print"arg:", Farg for inch args: Print " Other arg: " , Valuefun_var_args ("i", 313
2. The second scenario:
def fun_input_list (VAR1,VAR2,VAR3): Print var1,var2,var3var_list=["second", 3]fun_input_list (1,*var_list )1 Second 3
The essence of 3.**kargs is to store the parameters and values of the function in the Kargs variable of the dictionary type.
def Fun_var_kargs (farg,**Kargs): print"firsr value%s"% Farg for inch Kargs.keys (): Print Kargs[key]fun_var_kargs (1,var1="second", var2=35,var3=" Third " 1secondthird35
4.**kargs's second usage scenario
def fun_input_dic (var1,var2=2,var3=3): print var1,var2,var3dic_input={ " var2 ": 2,"var3":"third"}fun_input_dic ( 1,**dic_input)1 2 third
Use of *args and **kargs in big talk python