Python variable parameters

Source: Internet
Author: User

Original address: Http://docs.pythontab.com/python/python3.4/controlflow.html#tut-functions

One of the least common choices is to have the function call a variable number of arguments. These parameters are packed into a tuple (see tuples and sequences ). Before these variable number of parameters, there can be 0 to more common parameters.

def write_multiple_items (file, separator, *args):    file.write (Separator.join (args))

Typically, these mutable parameters are in the parameter list because they pass all the remaining input parameters to the function. last one

Any arguments that appear after *args are keyword parameters, which means that they can only be used as keywords, not positional parameters.

def Contact (*args,sep='/'):    return sep.join (args)

Call Function:

Contact ("wo","shi","wo" )

Output Result:

Wo/shi/wo

Python variable parameters

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.