The Python Game Book

code games. learn Python.

User Tools

Site Tools


Sidebar

Github:

en:glossary:l:legb

LEGB

LEGB stand for Local, Enclosing, Global, and Built-in.

The LEGB-rule is the order in witch python resolves namespaces. See also local and global scope.

  1. 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.
  1. 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.
  1. 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
  1. 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