Generator functions
Learn in depth →A function containing yield creates a generator whose execution suspends between yielded values.
def values():
yield expressionExample
def values():
print("started")
yield 10
g = values()
print("created")
print(next(g))Result
created started 10
Watch for: Calling the generator function does not execute its body immediately. Exhaustion ends that generator instance.
Practise this topic →