Use of *args and **kargs in big talk python

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.