In this video course, you’ve practiced working with scopes. Remember, 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 practiced:
- Identifying the scope of objects
- Working with the
global
keyword - Exploring the LEGB rule for scope resolution
- Using the
return
statement in a function
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.
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.
Pankaj Poddar on Nov. 19, 2024
Dear Team, In the summary it is mentioned that we have practiced global keyword, however I don’t recollect we have used the global keyword in this course yet.