- Defined function calls and function
- return action
- Defines three parameters
- Commonly built len () function
Function basis
Defined functions
def function name (parameter):
pass
return expression
pass here means nothing, do nothing
Behind the return you can return any expression, but can not be an assignment statement
return did not write the return value, the default None
The difference between the return and print
return is the return value of the function, the return value can be assigned to variables
The print just print out
Function naming rules
Letters, digits, and underscores, and variable naming consistency
Function call
Function name (parameter)
Function Arguments
Defined parameters
Mandatory parameter (when the function call, the essential parameters must be passed, also known as positional parameters)
Default parameter (when the function call, default parameter values can not be passed, the value is not passed, it will use the default parameters)
Variable length parameter (when the function call, variable length parameters may not pass, may be passed in any length, where the definition, parameters can be placed in the form of tuples foremost, rearmost only put a dictionary)
* Args: ** kwargs parameters other than the dictionary: dictionary parameters
Call parameters
Positional parameters (mandatory parameter), keyword parameter used directly in the function
None Type parameter in python, parameter can take any object, the code will be limited only the function of the parameter type
Built-in functions (understanding)
Built-in objects View: dir (_builtins_)
Simple built-in function
Common functions: len min for the minimum required length of the seek maximum sum sum max sorted in a forward direction is not reversed --- reverse reverse (returns an object, use the list () or a tuple () to change its type)
Base conversion function: bin oct converted into binary conversion hex hexadecimal octal ord chr ASCII characters to ASCII character code switch
Advanced built-in functions
It returns an enumerator can enumerate object (and the corresponding index value is taken out together)
eval taken out of the string as a valid string str evaluate expressions and return the results
exec execution string string compiled
Each element filter (function sequences) sequences filter passed as a parameter to a function to judge, then return True or False, and finally returns True new elements into the list
map (method name, parameters can be iterative) For each element the parameters are iterable fuction application function, and the result is returned as a list
zip objects one by one pair (extra elements, without pairing)