Caffeinated Coder
Book an appointment
Lesson 06 · Basics

Loops

A loop runs the same lines of code again and again, so you write a job once and let Python repeat it. Step through a four-line program, loop.py, that adds up the list [1, 2, 3] with a for loop: watch the loop variable take each item in turn, the indented body run once per item, and the total grow from 0 to 6. Finish with range(), which counts for you, and a look at the while loop.

12 min10 steps5 questionsBeginner
Fig 6 · Interactive
Loading figure…
or ← →

Quiz Unlocks after the last step.