- Programming method
- 1, process-oriented programming: According to business logic from top to bottom code to implement the function
- 2, functional programming: to encapsulate a function code in the function, the use of the same function later, no need to write, direct function calls can
- 3. Object-oriented programming: classify and encapsulate functions to make development "faster, better and stronger"
- function-type programming
- function definition
- will be able to implement some kind of function, reusable, organized code block together
- Functions of the function
- Enhanced reusability and readability of code
- function syntax
- def function name (parameter optional)
- function body (code block)
- Return
- The function returns the value return
- The result returned to the caller after the function has been executed (the caller is required to accept by defining the variable)
- The function ends when it encounters a return, no longer executes the following code, ends the function
- Do not write return, Python built-in rules return none by default
- Return None, returning none
- Return a single value that returns this single value
- Return multiple values, including multiple values in (tuples), returned to the caller (can be directly accepted by defining the deconstruction)
- function Parameters
- Parameter: A variable in the position of a function declaration that declares a variable in parentheses
- Position parameters
- Default parameters
- 1. The positional parameter must be declared before the default parameter can be declared
- Argument: The value that the caller actually passes to the function when it invokes the function
- Position parameters
- Keyword parameters
- Mixed parameters
- 1, position parameters and keyword parameters mixed use
- 2, must first write positional parameters, after the keyword parameters, or error: (syntaxerror:positional argument follows keyword argument)
- Ternary op-expression
- A = 1
- b = 2
- c = A If a > b Else B # C equals if A is greater than B, and no is equal to B
Python Basic-day9-function