Back to feed

Using Generators and yield in Python

Real Python
Using Generators and yield in Python

EDITOR BRIEF

Learn how to create Python generator functions and generator expressions using the yield statement. The article also explains when lazy evaluation—producing values as needed—can be useful.

INSIGHTS

Generators are useful for working with values one at a time. Try rewriting a simple function as a generator and compare it with a generator expression.

CodeFriends courses that build on this story. Practice in the browser with nothing to install.

COMMENTS

0/40
0/2000

Loading comments…