๐Ÿ PyQuest๐Ÿงบ Lists & Collections ยท ๐Ÿ” Looping Through a List
โญ 0 XP๐Ÿ Python is waking upโ€ฆ

Looping Through a List ๐Ÿ”

You already know for loops with range(). Here's the even better trick: you can loop straight over a list and get each item, one at a time.

pets = ["cat", "dog", "fox"]

for pet in pets:
    print(f"I love my {pet}!")

Output:

I love my cat!
I love my dog!
I love my fox!

The loop runs once for every item. Each time around, the variable pet holds the next thing in the list. You pick that variable's name โ€” it could be pet, thing, or banana. Pick something that makes sense!

No range(), no counting, no positions. Just "for each thing in the list".

Your mission

  1. Make a list called planets with at least 4 planets in it
  2. Use a for loop to print one sentence per planet
  3. Each sentence must include that planet's name โ€” use an f-string!

Your code

Press โ–ถ Run to see what your code does!