Level 50 of 50
Generators & yield
the grand finale: generators. Watch the reel, then work through it below: run the code, take the quiz, keep the cheat sheet.
📒 Open the cheat sheetSanaThe bank gives tokens one at a time. Not all 1000 at once!
TeacherSmart! Python can do that too. A generator, with yield!
bank.py
def tokens(): yield "A1" yield "A2" for t in tokens(): print(t)
TeacherEach yield hands out ONE token, then waits for the next request!
SanaWhy yield? Why not return?
Teacherreturn ENDS the function. yield just pauses it, and remembers where it was!
bank.py
def tokens(): n = 1 while True: yield n n += 1 g = tokens() print(next(g), next(g))
TeacherSo even an endless line is fine! next() asks for one more.
⏸ Pause & predict: what prints?
def gen(): yield 5 yield 10 g = gen() next(g) print(next(g))
Where this leads
Python is step one. Building AI that ships is the rest.
The diploma takes you from zero to deployed computer vision, LLM and agent projects, with engineers who build them for a living. Already code? The bootcamp does it in three months.