Every time Python encounters a variable name, it has to decide which value that name refers to. The answer depends on where the name is used. Python searches for names in a fixed order known as the LEGB rule: Local (inside the current function), Enclosing (inside any outer function that wraps it), Global (at the top level of the module), and finally Built-in (names like len and print that Python provides automatically). The first match wins, and if no match is found you get a NameError.
Scope matters in this course because you are now writing functions, and functions are the main way Python creates new scopes. Assigning to a name inside a function creates a local variable by default, even if a variable with the same name already exists outside the function. When you genuinely need a function to change a variable that lives elsewhere, Python requires you to say so explicitly with the global keyword (for module-level names) or the nonlocal keyword (for names in an enclosing function). Understanding this prevents a whole category of confusing bugs, such as a function that seems to update a counter but leaves the original unchanged, or an UnboundLocalError on a name you thought was global.
As you watch, keep three questions in mind for every example: where is this name first assigned, which scope does Python search first, and does this code read a variable or rebind it? Try predicting the output before the narrator reveals it, then pause and check. Pay particular attention to the difference between mutating an object (such as appending to a list) and reassigning a name, since only the latter triggers the need for global or nonlocal.
A beginner-oriented walkthrough of the distinction between local and global variables in Python, likely using small function examples to show what happens when a name is defined inside a function versus at module level. Based on the title and description, it should also demonstrate when and why you would reach for the global keyword to modify a module-level variable from inside a function.
CodeWithHarry's tutorial series is a well-known, slow-paced introduction, making this a good first pass at the Local and Global layers of LEGB and at the global keyword subtopic before you tackle nested functions.
This video covers defining functions inside other functions, how closures capture variables from an enclosing scope, and how Python resolves variable names across those nested levels. Given the title and the channel's style, expect precise explanations of why an inner function can read an outer function's variables, and where nonlocal becomes necessary to rebind them.
mCoding is produced by a professional Python developer known for technically accurate, detail-focused explanations, and this is the one video of the three that directly addresses the Enclosing layer of LEGB and the nonlocal keyword.
A short, focused explanation of the key asymmetry in Python scoping: inside a function you can read global variables freely, but assigning to a name makes it local unless you declare otherwise. The description suggests it works through what happens within each function call and why the read/write distinction trips people up.
Python Morsels produces concise, carefully worded lessons, and at just over four minutes this is an efficient review or reinforcement of the local-versus-global rule and the exact behavior that motivates the global keyword.
These three videos together support MO2, the ability to trace Python's LEGB scope rule and predict which value a name resolves to. The CodeWithHarry and Python Morsels videos build the Local and Global layers and the assignment-makes-it-local rule that underlies the global keyword, with the Python Morsels clip offering a compact restatement for review. The mCoding video extends the picture to the Enclosing layer through nested functions and closures, which is where nonlocal applies. Because scope is a property of functions, the examples also reinforce MO1 by showing how def creates a new namespace each time a function runs, and the mental model of per-call local scopes will be useful later when you trace recursive calls for MO3.
These videos were chosen from YouTube on October 2, 2026. Each has captions; the player turns them on. Videos on YouTube can be changed or removed — if one no longer plays, tell your instructor. If a player does not appear, use its Watch on YouTube link.