KnowledgeBoat Logo
|

Computer Science

How does Python resolve the scope of a name or identifier?

Python Modules

2 Likes

Answer

When we access a variable from within a program or function, Python follows name resolution rule, also known as LEGB rule. When Python encounters a name (variable or function), it first searches the local scope (L), then the enclosing scope (E), then the global scope (G), and finally the built-in scope (B).

Answered By

2 Likes


Related Questions