🚀 New batches open: Advanced Excel • Power BI • SQL • AI for Analytics — Book a free demo

Day 7 — Python for loops and range()

The whole point of programming: do the same thing to a thousand rows without writing it a thousand times.

Looping over a list

city is just a name you chose. Python fills it with each item in turn.

range()

It starts at 0 and stops before the number you give — five numbers, 0 to 4.

Building a total

This pattern — start at zero, add each item — is the foundation of every report you will write.

Filtering inside a loop

enumerate() when you need the position

zip() to walk two lists together

Looping over rows

Real data is usually a list of rows. Unpack each row as you go.

Try these yourself

  1. Print the numbers 1 to 10.
  2. Print only the even numbers up to 20.
  3. Total a list of prices with a loop.
  4. Print each name in a list with its position, starting from 1.
  5. Loop over rows of (name, amount) and print only those above 40000.

Ready for pandas and real projects?

This tutorial covers core Python. Our Data Analytics course takes you into pandas, NumPy, real files and visualisation, with mentor support and portfolio projects.

See the course →