Track 5 · Lesson 5 of 12
Scope: local and global variables
Understand where a variable exists, why assigning inside a function creates a local variable, and why global state causes trouble.
You will be able to
- Explain that parameters and variables assigned inside a function are local to that call
- Predict when a function reads a global variable and when it creates a local one
- Diagnose NameError and UnboundLocalError caused by scope
- Replace global state with parameters and return values
Included with a Formula Quest membership
It has 4 graded exercises with feedback, hints and solutions. Python Quest is included in Formula Quest memberships that cover Python; membership and billing are managed on Formula Quest.
View Formula Quest memberships
Tracks 1 and 2, the first lesson of every track, the playground and the dataset library are free.