Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
What are the basic scoping rules for python variables? How do these rules apply to various scopes like the local scope, built in scope, global scope and so on?
In the book Learning Python by Mark Lutz, he suggests the following mnemonic for remember how Python scoping works: LEGB
Going from the narrowest scope to the widest scope:
L stands for “Local”. It refers to variables that are defined in the local scope of functions.
E stands for “Enclosing”. It refers to variables defined in the local scope of functions wrapping other functions. G stands for “Global”. These are the variables defined at the top level of files and modules.
B stands for “Built in”. These are the names that are loaded into scope when the interpreter starts up.