KnowledgeBoat Logo

Computer Science

What is the order of resolving scope of a name in a Python program ?

  1. B G E L
  2. L E G B
  3. G E B L
  4. L B E G

Python Functions

1 Like

Answer

L E G B

Reason — When you 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