In this video course, you’ve learned about scopes. You can think of a scope as a set of names mapped to objects. When you use a particular name in your code, such as a variable or a function name, Python checks the current scope to determine whether that name exists.
A useful way to remember how Python resolves scope is with the LEGB rule. LEGB is an initialism for Local, Enclosing, Global, Built-in, which describes the order by which Python resolves scope.
In this video course, you’ve learned:
- What a scope is and why it’s important
- How Python applies the LEGB rule for scope resolution
Scope can be confusing, and it takes some practice for the concept to feel natural. Don’t worry if it doesn’t make sense at first. Just keep practicing and use the LEGB rule to help you figure things out.