Doing something to every item — a loop
P41.repeating-and-choosing.01 · Audience: guest, language-pro, it-ml · Prerequisites: Writing your own tiny function
Here is the move at the heart of automation. Picture a column of words and a task you repeat down the whole column: capitalise each one, or note how long each one is. On paper you go line by line, doing the same thing to each. A loop is that "go down the list, do this to each one" — written once, run for every item.
ⓘ Concept: A loop repeats a task down a list
for word in words: reads as "for each word in the list words, do the following." Python hands you the items one at a time — first "pear", then "apple", and so on — and runs the indented lines once for each. You write the task once; it happens to every item.Why it matters — Anything you do to a whole list by hand — every entry, every line — a loop does once and applies to all of them. It is the single idea that makes a notebook worth the trouble.
Ask the mentor about this module
Ask a question about this content. The mentor explains and grounds its answer in what you are studying; asking is recorded as a learning signal, not a grade.
🎓 Practice ladder
1 graded rung · ~5 minYour turn: loop over a list of words and build a new list holding a capitalised copy of each — do this to each one. Press Run.
Explorer rung — do something to every item
Loading exercise…
Where next?
Later in Repeating & Choosing
Go up a level