The LEGB-rule is the order in witch python resolves namespaces. See also local and global scope.
Local (or function) scope: variables that are defined inside a function (or lambda) have local scope. They exist only after the function is called. Each function call makes his own local scope, that's why recursion (where a function calls itself several times) works. See generators for functions that “remember” their variables between different calls.
Enclosing (or nonlocal) scope: For nested or inside functions, the enclosing scope is the scope of the outside or “parent” function, and it is visible inside the nested/inside function.
Global (or module) scope: everything that you define outside a function (at the left edge of the screen) has global scope and is also visible downwards inside the functions
Built-in scope: scope that is provided by the python language itself and always visible. Like keywords, expressions etc.
en/glossary/l/legb.txt · Last modified: 2020/12/15 19:33 by horst