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