What is a generator and what does yield do?
Model answer
A generator is a function that produces values lazily. yield returns a value and pauses the function, keeping its state until the next value is requested. Generators save memory for big or endless sequences and can be chained in pipelines.
Learn this topic
The Python Standard Library: Dates, Counter, Statistics and More in the course Python for Beginners: Learn to Code with Real Projects.
Sign in to add your own answer.