Python path-functions

Source: Internet
Author: User

I. Function classification

1. Built-in functions

2. Custom Functions

Two. Use of functions

1. Define First

(1) the process of preparing tool tools is called defining functions, and the built-in function interpreter is already defined and can be used Directly.

Example: def function name (test1,test2,test3):

function body

return value

There can be more than one return inside a function, but only to a return to end the call, return value as the Function's execution result returned, return value no type limit, no value, return None.

(2) the definition phase only detects syntax and does not execute Code.

(3) three types of function definitions:

No parameter function: just perform some operations, such as printing, user interaction

Parameter function: the corresponding logic needs to be executed according to the external parameters, such as statistical length, maximum number, etc.

Cases:

Empty function: Design Code structure

2. After use

Call the function procedure:

1. Find First Name

2. Call by name

Three types of function calls:

(1). Statement form: Test ()

(2). expression form: 2*len (' China ')

(3). arguments that can be used as another function

Three. parameters of the Function:

1. definition

parameter is variable name, argument is variable value

2. Specific applications

Positional parameters: parameters defined in order from left to right, with positional and positional arguments

Positional parameters: required parameter

Positional arguments: passing values to parameters by location

Keyword parameters: defined in key=value form

Note for keyword Parameters:

(1). The keyword argument must be behind the position parameter

(2). cannot repeat values for the same parameter

Default parameters: that is, the default parameter, that is, in the definition phase is already a parameter value, in the call stage can not pass Value.

Default parameter Considerations:

(1). The default parameter must be placed after the position parameter

(2). The default parameter is assigned only once, only once, in the definition Phase.

(3). The default parameter is best defined as an immutable type, string, or Number. (can type may change external values)

Variable long arguments: number of arguments

Processing mechanism: positional arguments are processed by *, and key arguments are handled by * *.

* Processing Example (the result is a tuple):

* * Processing Example (results received are dictionaries):

Python path-functions

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.