Python Generators 101

Have you ever had to work with a dataset so large that it overwhelmed your machine’s memory? Or maybe you have a complex function that needs to maintain an internal state every time it’s called, but the function is too small to justify creating its own class. In these cases and more, generators and the Python yield statement are here to help.

By the end of this course, you’ll know:

  • What generators are and how to use them
  • How to create generator functions and expressions
  • How the Python yield statement works
  • How to use multiple Python yield statements in a generator function
  • How to use advanced generator methods
  • How to build data pipelines with multiple generators

If you’re a beginner or intermediate Pythonista and you’re interested in learning how to work with large datasets in a more Pythonic way, then this is the course for you.

What’s Included:

Downloadable Resources:

About Christian Mondorf

Christian is an avid Pythonista and video instructor at Real Python.

» More about Christian

Each tutorial at Real Python is created by a team of developers so that it meets our high quality standards. The team members who worked on this tutorial are:

Participant Comments

Avatar image for Andy Pickett

Andy Pickett on Feb. 10, 2021

Fantastic explanation thank you! Really helped with a topic I’ve been struggling with in another course.

Avatar image for avalidzy

avalidzy on June 21, 2020

Excellent presentation! Would watch it again. Will find a way to use generators with Django. Thanks!

← Browse All Courses