Skip to main content
Loading page…
Python Mastery
Chapter 6
Lesson 3 of 4
Scope: The LEGB Rule
Contents
Notes
Tutor
Concept
The LEGB Rule Explained
Loading activity…
Previous
1 / 6
Continue
Contents
Notes
Discussion
Tutor
20 min
6 activities
0 of 6 done
In this lesson
1
The LEGB Rule Explained
2
Shadowing and Read-Before-Assign Errors
3
global and nonlocal
4
LEGB Scope Quiz
5
Gotcha: Built-in Names Are Not Reserved
6
Design Question: Refactor a Global
Objectives
Learner can trace name resolution through the Local, Enclosing, Global, and Built-in scopes
Learner can predict when a NameError will occur due to scope issues
Learner can use the global and nonlocal keywords deliberately and explain why overusing them is a code smell
Chapter 6 · Functions
Defining & Calling Functions
Arguments In Depth
Scope: The LEGB Rule
Recursion & Lambdas
Previous: Arguments In Depth
Next: Recursion & Lambdas