Python variable length parameter *args, **dictargs

Source: Internet
Author: User

1. the variable name with an asterisk (*) will hold all the unnamed variable parameters, cannot store dict, or error.

Such as:

1  defMultiple (ARG, *args):2      Print "ARG:", Arg3     #print variable length parameters4       forValueinchargs:5          Print "Other args:", Value6  7  if __name__=='__main__':8Multiple (1,'a', True)

Output:

2. the variable name with an asterisk (* *) holds all the unnamed variable arguments

1  defMultiple2 (* *args):2     #print variable length parameters3       forKeyinchargs:4          PrintKey +":"+bytes (Args[key])5  6  if __name__=='__main__':7Multiple2 (name='Amy', age=12, Single=true)

Output

3. There are *args and **dictargs:

1 defMultiple (ARG, *args, * *Dictargs):2     Print "ARG:", Arg3     #Print args4      forValueinchargs:5         Print "Other args:", Value6     #prints the indefinite length parameter of the dict type args7      forKeyinchDictargs:8         Print "Dictargs:"+ key +":"+bytes (Dictargs[key])9 Ten if __name__=='__main__': OneMultiple (1,'a', True, Name='Amy', age=12,)

Output:

Python variable length parameter *args, **dictargs

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.