Understanding Variable Scope in Python

Variable scope defines where a variable can be accessed within a program and how its name is resolved. Python employs lexical (static) scoping, where the structure of the code determines a variable's visibility, following the LEGB rule (Local, Enclosing, Global, Built-in)