table of Contents
Chapter 22. three forms defined function and the return value of the function
I. three forms defined function
1, no function parameter
- 1. When the medium is a defined function argument function body receives an external traditional values, in fact, the variable name
- 2. In the definition phase function, a function of no arguments in parentheses, the function is called with no arguments. Note that: no parameter definition, do not need to pass parameters when calling
- 3. If the logic function body does not depend on the value of the external mass, no parameters have to be defined as a function
del func():
代码块
2, reference function
- 1. In function definition stage, function parameters in parentheses, known to have a function parameter. Note that: when there is a reference definition, must be passed in parameter is called
- 2. If the function body to rely on external incoming logical value, there have to be defined as a function of parameters
del func(x,y):
代码块
3, empty function
- When you know the program needs a function, but do not know how to use the code, you can temporarily empty write a function and then to implement other functions, and then back up:
def func():
pass
II. The return value of the function
1. What is the return value
- Internal code function result obtained through a series of logic
2. Why do we need a return value
- If you need to get the result of the processing program for further processing function, it needs to function must have a return value
3, the return value of the function implemented by return
So what is the return
- 1.return function is a sign of the end, there can be multiple return within a function, to return as long as the execution, the function will stop
- The return value 2.return can return any data type
- Return Value 3.return no limit to the number that can be multiple return values separated by commas
- Return 0 value: return None
- It returns a value: The return value is the value itself
- Return multiple values: The return value is returned as a tuple