What Python keyword is used to yield a generator value? The keyword is yield. Placing yield in a function turns that function into a generator function, whose execution can pause and resume while producing a sequence of values.
When Python reaches yield, it returns the supplied value to the caller and preserves the generator’s execution state, including local variables and the next point of execution. A later call to next() resumes the function immediately after the yield statement. This makes generators useful for streaming data and representing large or infinite sequences without storing every value in memory at once.
The keyword is not next: next() is a built-in function used to request a value from an iterator. send() can communicate a value into a generator, but it is a generator method rather than the keyword that produces values. return ends a function; in a generator, return signals completion, while yield allows repeated production. Python introduced generators in version 2.2, and Python 3.3 added yield from for delegating to another iterable or generator.