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.
For more information on the concepts covered in this course, check out:
- Namespaces and Scope in Python
- Python Scope & the LEGB Rule: Resolving Names in Your Code
- Exploring Scopes and Closures in Python
- Python Inner Functions: What Are They Good For?
- Python 3’s f-Strings: An Improved String Formatting Syntax (Guide)
If you’re ready to continue your Python journey, then check out the other Python Basics courses.
Take the Quiz: Test your knowledge with our interactive “Python Basics: Scopes” quiz. Upon completion you will receive a score so you can track your learning progress over time:
Congratulations, you made it to the end of the course! What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment in the discussion section and let us know.