Skip to content
dreamcode
dreamcode
Back to map
Generators · Lesson 30 of 44
+15 XP on finish
PYTHON ADVANCED

Generators and Yield

A generator function yields values one by one using the yield keyword. It pauses execution after each yield, saving memory.

How it reads
yield count returns a value and pauses the function state
for number in ... calls next() implicitly to retrieve values
Cloud tip: Generators are perfect for looping over very large datasets or files that don't fit in memory.
main.py
PYTHON
real Python, runs in your browser
CONSOLE
- run your code to see output -