python--function

Source: Internet
Author: User

function is actually a function, a method, can simplify the code. function must be called before execution occurs.

Defined

Use Def to define a function, in which the formal parameters are passed in parentheses. He is a variable. function body is written in the function of the specific implementation of the part.

def say (name):

Print ("%s This is a function"%name)

When calling a function: Say ("Zhangfei") is called when the parentheses are the actual parameters. The number of parameters must also be consistent with the function.

Parameters

The parameters inside the function are called formal parameters. It can be a required parameter, or it can be a default value parameter. The form of expression is:

def say (name,sex= ' man ')

The formal parameter of a function is just a variable.

Call

When calling a function, the type of variable passed is not limited. The parameter name in the say function above can pass the actual parameters of the list type. When the default parameter of sex is not passed, the default value of ' Male ' is taken. If a parameter is passed. The value that is passed in is used.

Variable

The variables inside the function are local variables and can only be used within the function body. The function ends and the variable is gone.

return value

If you need to use the return value of the variable, write the return, and if you don't, then don't write return.

python--function

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.