Loading Loops...

Lesson 3
Introduction to For Loops

Learn how Python can repeat instructions for every item in a list. For loops help you write shorter, smarter programs.

🔁

Repeat Actions

Use a for loop to run the same instruction more than once.

📦

Loop Through Lists

Go through items like cat, dog, and fish one at a time.

🐍

Real Python

Run real Python code in the browser and check your answer instantly.

Watch First

Start with the video, then complete the loop challenge below.

How For Loops Work

A loop repeats code for each item in a collection.

Step 1

Start with a list of items.

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

Step 2

Create a loop variable. This variable stores one item each time the loop runs.

for pet in pets:

Step 3

Indent the code you want to repeat.

for pet in pets:
    print(pet)

Python Challenge

Loop through a list and print each pet.

Exercise: Loop through a list and print each item
Tip: use for pet in pets: and indent print(pet).
Loading Python…

🔁 Task

You are given this list:

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

Use a for loop to print each pet on a new line.

Expected output:

cat
dog
fish

The checker will make sure the list is unchanged and the output is correct.

Python Editor Press Ctrl + Enter to run
Terminal Output Program output and test results
Output will appear here…
The terminal shows your print() output and whether your for loop passed.

Keep Learning

Great job using loops to work with lists.

📚
0
Lessons Complete

You have practised Python basics, lists, and for loops.


Courses →
🏠
0
Home

Return to the KidzCode homepage.


Home →