Step: Generators: yield
Generators: yield
A function with yield is a generator: instead of returning once, it pauses and produces one value at a time as you iterate it.
Why it matters: generators produce values lazily (one at a time, on demand) instead of building a whole list in memory up front — essential for large or infinite sequences.
Example: def gen(): yield 1; yield 2 then list(gen()) is [1, 2].
Your turn: write countdown(n) that yields n, n-1, ..., 1, then print list(countdown(5)) to force it to produce all its values.
Pitfall: calling countdown(5) alone doesn't run any code yet — it just creates a generator object; the body only runs as values are pulled out (e.g. by list(...) or a for loop).
Your code:Expected output:
Step 17 of 18