Python indentation and colons
A colon at the end of a line starts a block. The lines inside the block are indented by the same amount (4 spaces), and the block ends when the indent ends.
Understanding Python indentation and colons in Years 7–8 Creating Digital Solutions
What it does: Both lines inside the loop block start with 4 spaces, so they line up and both belong to the loop. print("Done") is not indented, so it is outside the while block and runs only once the loop is finished. The line after a colon must be indented. Without the indent, Python gives an IndentationError. The standard in Python is 4 spaces for each level of indent. All lines in the same block must be indented by the same amount.
Common mistakes: The else line starts a block, so it must end with a colon. It should be 'else:'. Only a line that starts a block ends with a colon. This line is an ordinary instruction inside the loop, so it should have no colon: ' count = count + 1'.
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 50–125) and word search (Modules 3–125).
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
:Fill in the Blanks
Spot the Error
Student with a class code? Join your class →