Namespaces and Scopes
variables, functions
Divided into three kinds
#内置名称空间 built-in functions,
System functions are internally customized.
Python view built-in functions, commands:
Import Builtins
Dir (builtins)
#全局名称空间 file is written in the head, there is no indentation defined function or variable.
Once defined, it can be used anywhere in the entire file.
#局部名称空间
Once defined, it can be called within a local environment, such as a variable defined in a defined function, which can only be called inside the current function, and cannot be called outside the global or other functions.
External, or other defined function calls, will be an error!
Built-in and global namespaces collectively known as Global scopes
A local namespace is called a local scope
#先定义后使用!!!
Use the search process: Local find this layer can not find the words, will go up a layer of defined function to find, can't find---> global find, global find words---> from the system's built-in search
Query global Globals () Local: Locals () output to dictionary format
X=1
def func ()
Print ("from Func")
x=2
Print (Globals ())
function nesting and static nesting fields
#嵌套调用
#嵌套定义
Function object and Closure
A function is the first class of objects.
Functions can be assigned values,
The function can be passed as a parameter,
Think of the function as the return value,
Consider a function as an element of a container type.
#闭包
Definition: must first be an internally defined function that contains a reference to an outer scope instead of a global domain name word.
No value will return to none.
Non-parametric adorner
Python Full stack Python Foundation (ix) scoped function nesting closure