next()
.yield
statement represents the point of preemption. This is where executed last stoppeddef my_generator():
print("Starting up")
yield 1
print("Resuming")
yield 2
print("Ending")
gen = my_generator()
next(gen)
# Starting up
# 1
next(gen)
# Resuming
# 2
next(gen)
# Ending
# Traceback (most recent call last):
# File "<stdin>", line 1, in <module>
# StopIteration