Good place to stop if you're short on time — step 3 picks up here.
Lesson idea Tap to fold
In shots = ["wide", "medium", "close-up"], which number in square brackets gets you "close-up"?
Show the answer
Answer. 2 — because the count starts at zero, so the third item is two steps in from the front.
Repeat one operation for each item
Your outcome: Write a for loop that visits every clip in list order and prints one labelled line per clip.
for take in takes: assigns the next element to take on each iteration. takes is the collection; take is one current value, not the entire list. The loop variable name can differ, provided its use inside the loop agrees.
The colon starts a block. Indentation identifies the repeated statements; use four spaces consistently here. A print after the loop at the outer indentation runs once, not once per clip.
The + operator joins two strings. "Checked: " + take combines a constant prefix (including the space) with the current filename. This is text concatenation, unlike integer addition. An empty list performs zero iterations.
# Repeat one operation for each item
takes = ["take-a.mov", "take-b.mov", "take-c.mov"]
for take in takes:
print("Checked: " + take)
print("Done")
Trace: take is first take-a.mov, then take-b.mov, then take-c.mov. The indented print runs three times. Done is outside the loop and prints once after those three lines.
Use one repeated operation, not a separate hardcoded print for every clip. Add a fourth invented filename, predict its place, then try an empty list.
Predict, explain, then test
Answer before opening the comparison. These brief answers are self-reviewed, not quiz scores. Task labels describe the brief, not proof that you worked without assistance. Record any examples, hints or tutor help in your own Notes.
Predict
How many Checked lines does the worked loop print for an empty takes list?
Compare your answer · self-reviewed
Zero. Done still prints once because it is outside the loop.
Explain
Why must the name after for match the name used inside the repeated operation?
Compare your answer · self-reviewed
That name receives the current item. Referring to an unrelated or undefined name does not use the item supplied by this loop.
Repair
Only the last filename prints because print is outside the loop. What should change?
Compare your answer · self-reviewed
Indent the per-item print under for. Leave any one-time final message outside the loop.
Choose an exercise to load its prompt.
Today's idea in two other voices, if you want one. Not required — the exercises above are the actual lesson.
- Python for Loops: The Pythonic Way — article, Real Python
- Python Tutorial for Beginners 7: Loops and Iterations — video, Corey Schafer
Loading exercises…
Noted on your route map, with the step you were on. Nothing is lost by parking it — the next review day will bring this idea back, and the flag tells the course where to slow down.
The tutor mounts here when JavaScript is available. The lesson above stays readable without it.