Learn the basics of creating and using generators. In order to understand how asyncio
works, it is important to have a basic understanding of how generators work. In this lesson, you’ll learn how to turn a regular function into a generator using the yield
keyword.
You’ll also see a couple of examples like the one below that show how to create and use a generator to make a sequence of values.
def odds(start, stop):
for odd in range(start, stop + 1):
yield odd
Eddie on April 23, 2019
Not very important I guess, but I guess odds will give us even numbers if we use an even number as
start
and/or asend
, won’t it? Something like this could help avoid that: