Name Resolution: The LGB Rule
If the prior section sounds confusing, it really boils down to three simple rules:
Name references search at most three scopes: local, then global, then built-in.
Name assignments create or change local names by default.
“Global” declarations map assigned names to an enclosing module’s scope.
In other words, all names assigned inside a function def statement are locals by default; functions can use globals, but they must declare globals to change them. Python’s name resolution is sometimes called the LEGB rule, after the scope names:
When you use an unqualified name inside a function, Python searches three scopes—the local (L), then the global (G), and then the built-in (B)—and stops at the first place the name is found.
When you assign a name in a function (instead of just referring to it in an expression), Python always creates or changes the name in the local scope, unless it’s declared to be global in that function.
When outside a function (i.e., at the top-level of a module or at the interactive prompt), the local scope is the same as the global—a module’s namespace.
MNS Edu - related videos for programming languages are :-
Function intro
• Funtion - Intro | Python3
Types of function in python
• Types of function | Creating Function | Py...
Types of function call statement
• Types of Function call Statement | Python ...
Structure of program | _main_ function | _name_ built in variable
https://studio.youtube.com/video/V4uD...
Flow of execution in function call
• Flow of execution in function call | Pytho...
Fruitful & Non Fruitful function
• Fruitful & Non Fruitful Function | CBSE 11...
Local & global scope
• #Life time of Variable|#Global Scope|#Loca...