Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What does the global keyword do in Python?
The global keyword tells Python that a variable inside a function refers to the variable defined outside the function, at the global level. It allows you to change the global variable from inside the function.
Click to reveal answer
beginner
Why do you need the global keyword to modify a global variable inside a function?
Without global, Python treats variables assigned inside a function as local. Using global tells Python to use the variable from outside the function, so changes affect the global variable.
Click to reveal answer
beginner
What happens if you try to modify a global variable inside a function without using global?
Python creates a new local variable with the same name inside the function. The global variable remains unchanged outside the function.
Click to reveal answer
beginner
Show a simple example of using global to change a global variable inside a function.