Looping through a list with for...in
Runs the indented block once for each value in the list. The variable item holds the current value each time round, starting with the first and finishing with the last.
Understanding Looping through a list with for...in in VCE Software Development U3O1
What it does: The variable name holds a different value from names on each pass, so print(name) shows every value in order. The if is checked for every age in the list, but count only goes up when the age is 13 or more. A for loop line must end with a colon (:). Without it Python gives a syntax error. A for...in loop runs the indented block once for every value in the list. This list has 3 values.
Common mistakes: The loop variable is called pet, so item does not exist and causes a NameError. Inside the loop, use the loop variable: print(pet). nums is the whole list, so you cannot add it to a number. Add the loop variable n, which holds one value each time: total = total + n.
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
for item in my_list:Fill in the Blanks
Spot the Error
Student with a class code? Join your class →