3.4 - global and nonlocal Keywords
Enroll to start learning
You’ve not yet enrolled in this course. Please enroll for free to listen to audio lessons, classroom podcasts and take practice test.
Practice Questions
Test your understanding with targeted questions
What is a global variable?
💡 Hint: Think about where the variable is defined.
What does the global keyword do?
💡 Hint: It starts with a 'g' and lets you change a variable outside the function.
4 more questions available
Interactive Quizzes
Quick quizzes to reinforce your learning
What keyword do you use to modify a global variable inside a function?
💡 Hint: Remember its scope and where it's defined.
True or False: Nonlocal variables are defined outside the function.
💡 Hint: Consider the relationship of nested functions.
2 more questions available
Challenge Problems
Push your limits with advanced challenges
Create a small Python program that uses both global and nonlocal variables. Explain how they function within different scopes.
💡 Hint: Structure it such that each variable's value changes based on the function used.
Explain a real-world application where controlling variable scope with global and nonlocal could resolve a complex issue.
💡 Hint: Consider how user inputs might be global events while handling them privately in specific cases.
Get performance evaluation
Reference links
Supplementary resources to enhance your learning experience.