The location where we can find a variable and also access it if required is called the scope of a variable.
- Python Local variable: Local variables are those that are initialized within a function and are unique to that function. It cannot be accessed outside of the function.
 - Python Global variables: Global variables are the ones that are defined and declared outside any function and are not specified to any function.
 - Module-level scope: It refers to the global objects of the current module accessible in the program.
 - Outermost scope: It refers to any built-in names that the program can call. The name referenced is located last among the objects in this scope.
 
Scope in Python refers to the visibility and accessibility of variables and objects. It determines where in a program a variable can be accessed. Python follows the LEGB rule, which includes local, enclosing, global, and built-in scopes. Variables defined in narrower scopes take precedence over wider scopes. Proper understanding of scope is important for avoiding naming conflicts and ensuring desired program behavior.
In Python, the concept of scope is closely related to the concept of the namespace. As you’ve learned so far, a Python scope determines where in your program a name is visible. Python scopes are implemented as dictionaries that map names to objects. These dictionaries are commonly called namespaces.
