Further Uses of the yield from Construction

Learn more about the yield from construction in Python.

Let's explore the real use of the yield from construction.

Capturing the value returned by a subgenerator

In the following example, we have a generator that calls another two nested generators, producing values in a sequence. Each one of these nested generators returns a value, and we will see how the top-level generator is able to effectively capture the return value since it's calling the internal generators through yield from:

Get hands-on with 1400+ tech skills courses.