Problem Statement
In a generator, how does 'return value' behave?
Explanation
A bare return stops the generator. A return with a value raises StopIteration carrying that value. It can be observed by a caller that drives the generator manually or via yield from.
This is useful for communicating a final result from a subgenerator to its delegator.
Code Solution
SolutionRead Only
def g():
yield 1
return 99
# next after yield raises StopIteration(99)