Namespaces
def: the name of a range of works
Global and local variables
- Local variables
Variable defined within the function
- Global Variables
Not in the function inside the definition of variables
Global 和 local
Through print(globals())
and print(locals())
see all of the current global and local variables
LEGB rules
The so-called LEGB means: locals, enclosing, globals, when the builtins (topical, closures, global, built-in), to find the variables, a sequential search in accordance with the above, if there is a local variable, to use local variables; if no local variables, but using where the variable is in the closure, check to see if the external function has the variable, if so, use the variable; if the external function has not the variable, and then see if there is a global variable, if any, using the global variable; If the above are not found, then the built-in module to find.
ps: how to see things built modules? : Dir (__ builtin__)