Generators
Generators and yield
yieldThe primary use of a generator is to produce values for use in iteration. Here's an example:
def countdown(n):
    print('Counting down from', n)
    while n > 0:
        yield n
        n -= 1
# Example use
from x in countdown(10):
    print('T-minus', x)Restartable Generators
Generator Delegation
Using Generators in Practice
Enhanced Generators and yield Expressions
yield ExpressionsApplications of Enhanced Generators
Generators and the Bridge to Awaiting
Last updated
Was this helpful?