[Python] Function parameter small note

Source: Internet
Author: User

    • function parameter Pattern matching overview
with the keyword
syntax position explanation
func (value Caller General parameters: Location matching
func (name= Value) Caller Keyword parameter: Key value matching
func (*SEQ) Caller Unpack the sequence as a regular parameter and pass the parameter
func (* * dict) Caller Unpack the dictionary as a keyword parameter and pass the parameter
def func ( Name) function definition General parameters: Location matching or variable name matching
def func ( Name=value) function definition Set default parameter value
def func (* Name) function definition Collect parameter composition sequence
def func (* * Name) function definition Collect parameter composition dictionary
def func (* args, name) function definition Force the name parameter to pass the
    • Use the * parameter to force the use of the keyword-only parameter and indicate that a variable quantity parameter is not accepted. Compare the following example:
      # 1def f(*, a):return aprint(f(1, a=‘kopara‘)) # => error# 2def f(*_, a):return aprint(f(1, a=‘kopara‘)) # => kopara
    • The keyword parameter must be preceded by the dictionary collection/unpacking parameters to avoid ambiguity.
?

[Python] Function parameter small note

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.