In Excel you wrote one formula and dragged it down every row. Python's for loop is the same move: write the step once, and it runs once per item in a list. This is a notebook — type a line in a cell and press Shift+Enter (or click Run) to execute it. The output appears right under the cell, like Jupyter or Colab. The Python is real, running sandboxed in your browser.
Same three invoice amounts. On the left you drag =B2*1 down column C and Excel
evaluates it once per row. On the right the loop body runs once per item. One step, repeated down the column.
| B (amount) | C (=B*1) | |
|---|---|---|
| 2 | 1200.00 | 1200.00 |
| 3 | 340.50 | 340.50 |
| 4 | 89.00 | 89.00 |
for amount in amounts: # this line runs once per amount print(amount)
Each Excel cell that fills in = one trip through the loop body.
Predict the output first, then run and compare. Edit any cell and re-run it — that is how you learn what each line does.
0 and add to it with total += amount
inside the loop, the way a running-total column carries the sum down the page. Iterate rows — loop over
a list of records (each a dict) and pull fields out by name, like reading across one spreadsheet row at a time.
Every one of these is "do this once per row," which is exactly what dragging a formula down does.