python--the parameter list

Source: Internet
Author: User

  When you want to pass the argument is already a list, the function calls to accept separate parameters, this time can consider the parameter list split:

    • You can use the * operator to automatically disassemble the parameter list:

args=[3,6]x=list (range (*args))print x

-------------------Output-----------------------------

[3, 4, 5]

    • You can use the * * operator to split the keyword argument into a dictionary:

defParrot (voltage,state='a stiff', action='Voom'):    Print "--This parrot wouldn ' t", Action,Print "If you put", Voltage,"volts through it.",    Print "E ' s", state,"!"D={"Voltage":"Four million"," State":"bleedin demised","Action":"Voom"}parrot (**D)


-------------------Output-----------------------------

--This parrot wouldn ' t voom if you put a four million volts through it. E ' s bleedin demised!

python--the parameter list

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.