Index Ai Academy
Glossary · Phase 7 · Software engineering

Generator function

Also written: generator functions, generator expression, generator expressions

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.

Create a free account See what's in the lesson

Other terms from the same lesson

Never trained an AI?

Teach a small one to write, right in your browser. It takes about 20 seconds and needs no account.

Teach it to write