Name space:
Built-in namespaces: When opening pytharm is loaded
Global namespaces: When running a py file is loaded
Local namespace (temporary namespace): loaded when called in a py file
def func ():-----> Function definition
Pass-------> function body
Func ()-------------> function call
function definition: Only the corresponding relationship of function name is stored in memory, and the contents of function body are not stored
Function call: Executes the contents of the function body, creates a temporary space, and as the function executes, the contents of the temporary namespace in memory are emptied
Scope:
Global scope: Content in the built-in namespace + content in the global namespace
Local scope: Local namespace
Order of Values:
Local---> Global---> Built-in, one-way value, irreversible.
A=10b=20def Test5 (A, b): print (A, b)---> 20,10 a=3 b=5 print (A, b)---> 3,5c = TEST5 (b,a) print (c) ---------> None
Load Order:
Built-in namespaces
Global namespaces
Local name space
Nesting of functions:
See the call on the Execute
Global and nonlocal (when the data type is immutable, you need to declare it, but when the data type is a list, you can add data directly to the list using append and directly cause changes to the global variables)
Global: Declare that the elements within a function can be global variables (functions can directly refer to global variables, no global variables are not changed by the function)
Nonlocal: Declares that a child function can change a variable of a parent function, but nonlocal cannot change a global variable (a child function can directly reference a variable of a parent function, and no nonlocal cannot change the parent function)
Count = 1def func1 (): count + = 1 # will error # count = 2 will not error
Def func1 (): count = 666 def inner (): print (count) def func2 (): nonlocal Count # Global count< C6/>count + = 1 print (' func2 ', count) Func2 () print (' inner ', count) inner () print (' func1 ', Count) func1 () print (count)
Python learns day, namespace and scope, nested functions, Global and nonlocal