python-Function-Parameters

Source: Internet
Author: User

The function is to combine a bunch of statements together to form a part:

1. Maximum code reuse, minimal code redundancy
2. Process decomposition, function is about the process, tell you how to do things

Parameter description for function passing



The red section is especially careful, otherwise there will be syntax errors, and another is that if given the default value of the parameter, it must be placed in the absence of the default value of the argument, put in front of the same syntax error,

* Star args returns the tuple tuple meta-progenitor star args Returns a dictionary

python defaults to matching variable names from left to right , and for arguments, underlining is the best way to learn
Country not given is the default CN

...

def f (a,b,c)
Prin (A,B,C)
F (a)
Output: 1 2 3
...

keyword Parameters , position-based parameters are first matched from left to right, followed by keyword matching, that is, if a keyword is used to pass a parameter, the parameter is passed through the variable name and is no longer a position.
...

F (1,b=3,c=2)
1 3 2
...

The default parameter is to invoke the function without passing the default value, pass the value of the pass

...
def f (a,b=2,c=3):
Print (A,B,C)
F (1)
F (+)
F (1,c=2,b=3) can be
...

keywords and default parameters mixing cases It's easy to see the excitement

any parameter with these two examples can be understood, a tuple, a dictionary

Finally this mix is also very good to use, draw a good line at a glance

Another knowledge point is the unpacking function, said the call function when the parameters passed with an asterisk, to be unpacked, solve the tuple, solve the dictionary.

python-Function-Parameters

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.