Tenth, Python function argument assignment order

Source: Internet
Author: User

FIX: Problem with function call assignment order


01, usually one by one corresponding assignment (with predefined values can not be assigned value)-------recommended ******

02, parameter one by one assignment can be specified

03, a parameter with a predefined value cannot take precedence over a parameter that has no pre-defined value assigned

Note: 01 in the case of a call, do not write the parameter name.

02 in the case of a call, specify: Parameter name = value (all the visible parameters are indicated)

EG1:

def test_e (n1,n2,n3=15):
N=n1+n2+n3
return n

01 corresponding Calling Method: S=test_e (4,1) n3=15

S=test_e (4,1,12) n3=12

02 corresponding Calling Method: S=test_e (4,n2=1) n3=15

S=test_e (4,n2=1,n3=12)

S=test_e (n2=1,n1=4) n3=15

03 corresponding Call Method: S=test_e (n3=14,n2=1,n1=4)----OK

S=test_e (n3=14,n2=1,4)--------No

S=test_e (n3=14,1,4)-----------No

Reason for two No in 03: parameters that have predefined values cannot be assigned precedence over parameters that do not have predefined values.

S=test_e (4,n1=1)--------------No

Cause: 4 is assigned to N1 by default, N1 cannot be assigned repeatedly

S=test_e (4,1,n3=15)-----------OK



Tenth Python function argument assignment order

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.