5. Python function

Source: Internet
Author: User

5-1. Definition of function

1. What is a function? Popularly speaking, function is the meaning of function, function is used to encapsulate a specific function, the function is divided into two types, one is the system itself, not we write its function system itself, such as Len () This function, the other is a custom function, we need to write its own function, this function of high degree of freedom; 2, definition and invocation of functions: format:def function name (): function content; function content function content; function content 5-2. Participate in the actual parameter 1, the concept of parameters in the function:Parameters are the data that the function uses to perform the function;  2. What are formal parameters? Formal parameters generally occur in the process of function definition, formal parameters usually refers to the name of the parameter, but not the value of the parameter, he is only the formal parameter, only a function of the name of which the position has a parameter only. 3. What are actual parameters? The actual parameter and the formal parameter just make up each other, the actual parameter usually appears in the function call, generally refers to the parameter concrete value;  4, the transfer of parameters:In Python, the arguments are passed in sequence when the function is called: The parameter is passed, as above, 2 is passed to a,8 to B; 5 . Key parameters: In Python, when there are multiple parameters in a function, we can assign values directly to our parameters by their names, so these parameters are called key parameters; 5-3. Function usage and return value Example 1: The case of a return value and multiple return values, with multiple return values stored together in the form of a Shime thought tuple, output as follows: Case 2: When multiple return values are stored separately: 5-4. Document String 1. What is a document string? The document string is proposed to solve the clutter caused by too many functions, which is unique in Python, that is, at the beginning of each function with a line of descriptive text, this line of descriptive text we call the document string;  2. How do I use a document string? The document string is generally multi-line, and the second line must be empty, not write things; the first line summarizes function functions, the third line begins to write the function-specific information; the space for the document string is as follows: The document string must be enclosed in three quotation marks; the end of the document string must be preceded by a period The first letter of the document string (if it is in English) must be capitalized;

5. Python function

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.