Lazo Lab Sign up

Read Python Like a Pro / Reading code

Lesson 5 of 10

Reading loops over lists

A for loop gives you one item at a time. Read it as 'for each item in this list, do the indented block'.

Key points

  • The loop variable changes each round
  • The block runs once per item
  • Code after the loop runs once, at the end
for fruit in ["apple", "kiwi", "fig"]:
    print(fruit.upper())
print("done")

Your turn

Add a counter so the loop prints 1 APPLE, 2 KIWI, 3 FIG. Hint: enumerate(list, start=1).

Watch a video on thisOpens YouTube search results for “Reading loops over lists” in a new tab

Quiz · +10 XP

How many lines does this print?

Log in to save progress and earn XP.