Python Beginner 17th Day function (1)

Source: Internet
Author: User

17day

Function

1. Function definition:

A function is a collection of a set of statements encapsulated by a name (function name), to execute the function, simply call its name

2, the function of the characteristics:

A reduce duplicate code

b makes the program extensible

C makes the program easier to maintain

3, formal parameters, actual parameters

Parametric: Allocates a memory unit only when it is called, releasing the allocated memory unit immediately after the call is completed. Therefore, the formal parameter is only valid inside the function. After the function call finishes returning the calling function, you can no longer use the shape parametric

Arguments: Can be constants, variables, expressions, functions, and so on, regardless of the amount of the actual argument, they must have a definite value when making a function call to pass these values to the formal parameter. Therefore, an assignment, input, and so on should be used to obtain a definite value for the argument.

4. Default parameters

The default argument is written after the non-default parameter, which is not specified at the time of invocation, and is the default value. If specified, the specified value is used

5. Key parameters

Under normal circumstances, to pass parameters to the function in order (order parameters), do not want to be in order to use the key parameters, only need to specify the parameter name (parameter named parameter is called the key parameter)

Note: Key parameters must be placed after the position parameter

6, non-fixed parameters

Multiple parameters can be passed

Method One: To implement the non-fixed parameter *args in the way of tuples, if the parameter appears *, the parameters passed is no longer a fixed number, all the parameters transmitted to the tuple

Method Two: Realize the non-fixed parameter **kwargs in the way of the dictionary

Python Beginner 17th Day function (1)

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.