python-when defining a function, the default value parameter cannot be placed before the required parameter in the variable length parameter

Source: Internet
Author: User

If a function parameter contains a default parameter, then all parameters after this default parameter must be the default parameter, otherwise it will be error: syntaxerror:non-default argument follows default argument

For example:

#-*-Coding:utf-8-*-
def test (a=11,b,c): #默认值参数不能放在必选参数前面
Print (a)
Print (b)
Print (c)

Test (11,22,33)

Correct:

# -*-coding:utf-8-*- def Test (a,b,c=33):    print(a)    print(b)     Print (c)    test (11,22,33)

Output Result:

112233***repl closed***

python-when defining a function, the default value parameter cannot be placed before the required parameter in the variable length parameter

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.