Python Scope
LINKS
- Python Scope & the LEGB Rule: Resolving Names in Your Code
- Video: Don’t be CONFUSED by BIG O notation anymore!
- Video: Big O Notation
- Rolling Dice Examples
Python Scope & the LEGB Rule: Resolving Names in Your Code
Understanding Scope
In programming, the scope of a name defines the area of a program in which you can unambiguously access that name, such as variables, functions, objects, and so on. A name will only be visible to and accessible by the code in its scope. Several programming languages take advantage of scope for avoiding name collisions and unpredictable behaviors. Most commonly, you’ll distinguish two general scopes:
-
Global scope: The names that you define in this scope are available to all your code.
-
Local scope: The names that you define in this scope are only available or visible to the code within the scope.