I love python. Position parameter, keyword parameter, default parameter

Source: Internet
Author: User

1. Position parameter:>>> def Check_web_server (host, port, path): Print ... >>> check_web_server (' www.python.org ', 80, '/') three parameters Shun The order must be one by one, and less than one parameter 2, (in the function call) keyword parameters:It can make the function clearer and easier to use, and also clears the order requirements of the parameters, which are specified by "key-value" for function calls >>> Check_web_server (port=80, host= ' Www.python.org ', path= '/') (three parameters of the location can be arbitrary) 3, (in the function signature) default parameters:Providing default values for parameters, which are not required to pass parameters to them, is used for function definitions (note: All positional parameters must be present before optional parameters, including function definitions and invocations) >>>defCheck_web_server (host, port=80, path= '/'):# the right Print ...>>>defCheck_web_server (path= '/', Host, port=80): # wrong (the location parameter host must be first on the front) Print ...>>> check_web_server (' www.python.org ') # OK (port and path are default values)>>> check_web_server (' www.python.org ', port=8080)  # OK (path is the default value)>>> check_web_server (port=8080, ' www.python.org ') # No (position parameter must be at the front)

I love python. Position parameter, keyword parameter, default parameter

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.