Glossary · Phase 7 · Software engineering
Generator function
A function that uses yield to hand out values one at a time, pausing between them, instead of building a whole list.
Try it now
Step through: the generator's body only runs when next() or list() asks for a value, and each yield pauses it with n still remembered.
Learn it properly
Iterators and generators · The iteration protocol, yield, lazy pipelines and itertools, in small memory. About 40 minutes.
Other terms from the same lesson
- iterator: An object that gives the next item each time next() is called, and is used up when it runs out.
Never trained an AI?
Teach a small one to write, right in your browser. It takes about 20 seconds and needs no account.