function parameters in Python

Source: Internet
Author: User

Reference: Http://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/ 001431752945034eb82ac80a3e64b9bb4929b16eeed1eb9000

Example 1:

def F (a,b=1,*x,c=9,d,**y): ...      Print ([a,b,x,y,c,d]) ...

Example 2:

def F (a,*, c,d): ...      Print (a,c,d) ...

The order of the parameter definitions must be: required, default, variable, named keyword, and keyword parameters.

A: Positional parameters must be passed in

B: The default parameter can not be passed in, but it is different from the default value of other types

X: Variable parameters are not passed in, default () tuple type, can be passed in multiple, type can be different

*,c,d: The named keyword parameter must pass in, can set the default value, if there is a mutable parameter in front of it, can omit *, pass in the form "Variable name = value"

**y: keyword parameter is not passed in, default to {} dictionary type, can pass in multiple values, in x=1 format, (key value pair)

function parameters in Python

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.