[Python] [Oldboy] keyword parameters and positional parameters, default parameters, variable length parameters (nameless, famous)

Source: Internet
Author: User
Tags function definition

The keyword parameter and positional parameters are defined when the function is called

Keyword parameters are key-value pairs appear, unordered, one more no, less one not

Positional parameters, orderly, one more no, one less.

Mashup: All positional parameters must be on the left side of the keyword parameter

  

The default parameter is defined in the function definition and can be used without arguments when the function is called.

Variable length parameter: *args, **kwargs

Mixing of variable length parameters and positional parameters

1 defAdd (x, y):2     returnX +y3 defAdd_1 (x=0, Y=1):4     returnX +y5 6 defList_add (x, *args, * *Kwargs):7     Printx8     Printargs9     PrintKwargsTen  One Print "function position parameter%d"% Add (1,3) A Print "function keyword parameter:%d"% Add (x=2, y=4) - Print "function default parameter%d"%add_1 () - Print "function position keyword mash%d"% Add (0, y=2) theList_add (1, 2, 3, 4, name=1) -List_add (1,*[2,3,4],**{"name": 1})
View Code

1 function Position parameter 42function keyword parameter: 63function default Parameter 14function position keyword mash up 2516(2, 3, 4)7{'name': 1}819(2, 3, 4)Ten{'name': 1} One  AProcess finished with exit code 0
View Code

[Python] [Oldboy] keyword parameters and positional parameters, default parameters, variable length parameters (nameless, famous)

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.