What is a Python generator?

Python Developer Easy

Python Developer — Easy

What is a Python generator?

Key points

  • Generators produce values one at a time
  • They use the yield keyword to return values
  • Generators do not load all values into memory at once
  • Iterating over a generator is more memory-efficient than creating a list
  • Generators are useful for working with large datasets

Ready to go further?

Related questions