Definition of the function:
Functions are well-organized, reusable, code snippets for single, or associated functionality
Role of the function:
function can improve the modularity of the application, and the reuse of the Code
Any incoming parameter and first line statement can optionally use a document string-----for storing function descriptions
Function contents start with a colon, and indent
Basic format:
def wrapper () #函数的定义
Print (xxxxxxx)
Wrapper () #函数的调用
The return value of the function:
Return
Once the return is encountered, the entire function is ended
Return a value:-------> Only need to add a return at the end of return
return 18
Returns multiple values:--------> can return multiple values, any type of value
Parameters of the function:
Formal parameters: Def wrapper (formal parameters)
Arguments: Wrapper (argument)
Stand at the argument angle: Position parameter, key-word-pass-parameter, mixed-pass parameter
Standing parameter angle: Positional parameters must be passed
--------------------------------------------
Positional parameters default parameter dynamic parameters
corresponding Gender (*args,**kwargs)
--------------------------------------------
To pass the parameter:
Dynamic parameter transfer
---------------------------------------------------------------------------
Namespaces and Scopes
Namespaces:
1. Global namespaces
2. Local namespaces
3. Built-in namespaces
Load Order:
Built-in namespaces (load before program runs)
Global Namespaces (Program running: loading from top to bottom)
Local namespace (program run total: Before the call is loaded)
Order of Values:
In local calls: Built-in namespaces, local namespaces, global namespaces
Global invocation: Built-in namespaces, global namespaces
Scope:
Global scope
Local scope
Global: Local Call to Globals
Locals
Nonlocal: References and modifications to the variables of the parent scope, and to which layer it is referenced, all occurrences of the variable from that level and below
Name of function:
The function name essence is the memory address of the function
Closures:
intrinsic function references to external scope variables, called closures (non-global scopes)
Intrinsic functions:
functions defined inside a function are called intrinsic functions
def func ():
name = ' Taibai Venus '
def inner ():
Print (name)
intrinsic function references to external scope variables, closures
name = ' Taibai Venus '
def inner ()
Print (name)
----------------------------------------
Intrinsic functions:
name = ' Taibai Venus '
def inner ()-----------> intrinsic functions defined inside the function
Print (name)
python-Primary Knowledge function