Changing a global variable with the global keyword
A keyword used inside a function so it can assign to a variable defined outside all functions, instead of creating a new local variable with the same name.
Understanding Changing a global variable with the global keyword in VCE Software Development U3O1
What it does: The global line comes before the assignment, so score = score + 1 changes the outer score rather than making a local one. The function only uses its own parameter and returns a result, so it cannot change other parts of the program by accident. This makes it easier to test and debug. A function can read a global variable freely. The global keyword is only needed when the function assigns a new value to it.
Common mistakes: The keyword is misspelt, which causes a SyntaxError. It must be 'global score' so the function can change the outside variable. A function header must end with a colon. It should be 'def increase():'.
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 72–96) and word search (Modules 72–113).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
globalFill in the Blanks
Spot the Error
Student with a class code? Join your class →