Commenting out code to isolate a bug
Putting # in front of a line, or a selected block, stops Python running it. Use this to isolate a bug, then remove the # to restore the code.
Understanding Commenting out code to isolate a bug in VCE Software Development U4O1
What it does: Deleting the # turns the comment back into live code, so Python runs the line again. If the error goes away with the line disabled, that line is the likely cause of the bug. A # only affects its own line. Selecting the block and using the shortcut (for example Ctrl+/) adds # to every selected line. Each line needs its own # to be disabled. In the wrong choice, only the first line is disabled, so the other two lines still run. Commenting out isolates the cause. The program may now be missing a feature, so you still need to fix the line and restore it.
Common mistakes: // is not a Python comment, so Python tries to run it and raises a SyntaxError. To disable the suspect line, put # at the start: # average = total / 0. A # only disables the text after it. Here the code comes first, so y = x / 0 still runs and causes a ZeroDivisionError. Put the # at the start of the line instead.
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 125–171) and word search (Modules 115–171).
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
# (commenting out)Fill in the Blanks
Spot the Error
Student with a class code? Join your class →