What is Scope Resolution in Python?
Question
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
It will take less than 1 minute to register for lifetime. Bonus Tip - We don't send OTP to your email id Make Sure to use your own email id for free books and giveaways
Answers ( 2 )
Python Follows LEGB rule to look for variables:
LEGB Rule:
• L: Local — Names assigned in any way within a function (def or lambda),
and not declared global in that function.
• E: Enclosing function locals — Names in the local scope of any and all
enclosing functions (def or lambda), from inner to outer.
• G: Global (module) — Names assigned at the top-level Of a module file,
or declared global in a def within the file.
• B: Built-in (Python) — Names preassigned in the built-in names module :
open, range, SyntaxError,…
Scope resolution is way to find the place from which value of the variable come.
Python scope resolution follow LEGB rule:
L : Local ( values inside the function)
E: enclosing (values inside the nested function)
G: Global (values assigned at the top of the module)
B: built in (value which is there inside the built in package of python