Skip to Content
Nextra 4.0 is released 🎉

Loops

A loop repeats a block of code. Instead of copy-pasting the same lines over and over, you write them once and tell Python how many times to run them.

Python has two kinds of loops:

  • for loops — run once for each item in a sequence (a list, a range of numbers, etc.)
  • while loops — keep running as long as a condition is true

Each time a loop runs through its block of code is called one iteration.

Use the links below to learn how each one works.

Last updated on