yield values lazily, one at a time—stream huge data in constant memory.
A function that hands back one item at a time and pauses in between, instead of building the whole list in memory first.
It's how you process a file bigger than your RAM, and the mental model behind every streaming API you'll write.
A generator function contains yield; calling it returns a lazy generator object that runs no code until iterated. Each yield emits one value and suspends, freezing local state so it resumes exactly where it left off. This streams data in constant memory instead of building a full list.
A generator produces values lazily using yield: each call to next() runs the function until the next yield, hands back one value, and pauses with all local state intact. That means constant memory—you never materialize the whole sequence—so it's ideal for streaming large files or infinite sequences. A generator expression is the same thing inline, using parentheses instead of a list's brackets.
Generators in Python || Python Tutorial || Learn Python Programming — Socratica, 8:31