Deck 5: For Loops

0.0(0)
Studied by 0 people
call kaiCall Kai
Locked
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/4

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 9:05 PM on 8/10/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

5 Terms

1
New cards

What does this loop print?
samples = ['sample_A', 'sample_B', 'sample_C']

for s in samples:

print('Processing:', s)

"Processing: sample_A", "Processing: sample_B", "Processing: sample_C" → one line per item

2
New cards

In a for s in samples: loop, what is s?

A temporary variable that takes on each value in samples, one at a time, reassigned each pass → not a fixed name for one item.

3
New cards

What values does i take in for i in range(5):?

0, 1, 2, 3, 4 → five values, starting at 0.

4
New cards

Why does range(5) produce 0 through 4, not 1 through 5?

Same "up to but not including" logic as slicing → range(5) produces exactly as many indices as there are valid positions in a 5-item list.

5
New cards

What's the typical pattern for processing a list of files in a loop?

Loop over the list of filenames, load each one, compute something, and print or store the result → a template for most batch data-processing tasks.