+1 vote
in Class 12 by kratos

Explain LEGB rule.

1 Answer

+3 votes
by kratos
 
Best answer

LEGB rule: when a name is encountered during the ***** of the program, it searches for that name in the following order:

L. Local – It first makes a local search, i.e. in a current def statement.

E. Enclosing functions – It searches in all enclosing functions, from inner to outer.

G. Global (module) – It searches for global modules or for names declared global

B. Built-in (Python) – Finally it checks for any built-in functions in Python.

...