Last Updated: May 22, 2026
A function becomes a generator when it contains yield. This lesson focuses on yield itself: what it does to a function, how it differs from return, how it interacts with try/except/finally, and the lesser-known form value = yield x where the generator receives data back from the caller. The mechanics here are the foundation for everything from streaming pipelines to the coroutines that eventually grew into async/await.