There are use-cases where you don't want the function that yield
s to stop after that one yield
.
def iterate_me_please():
for i in range(10):
yield from range(i+1)
If you used return range(i)
or return range(i).__iter__()
, you would terminate the for
loop after one iteration.