๐ŸŽ New User? Get 20% off your first purchase with code NEWUSER20 ยท โšก Instant download ยท ๐Ÿ”’ Secure checkout Register Now โ†’
Menu

Categories

Python Intermediate

What is Generator?

A function that yields values one at a time using the yield keyword, enabling memory-efficient iteration over large datasets.

Generators produce values lazily โ€” they compute the next value only when requested. This makes them ideal for processing large files, infinite sequences, or data streams without loading everything into memory.

A generator function uses yield instead of return. Generator expressions use parentheses: (x**2 for x in range(1000000)) creates a generator without allocating memory for all values.

Related Terms

Python Iterator Protocol
The interface requiring __iter__() and __next__() methods, enabling objects to be used in for loops and other iteration contexts.
Flask
A lightweight web framework for Python that provides essentials for building web applications without imposing structure.
Python ABC Module
The Abstract Base Classes module that enables defining interfaces and abstract methods that subclasses must implement.
Type Hints
Optional annotations that indicate the expected types of variables, function parameters, and return values.
Pip Requirements File
A text file listing Python package dependencies with version specifications for reproducible project installations.
SQLAlchemy
The most popular Python SQL toolkit and ORM that provides a full suite of database abstraction patterns.
View All Python Terms โ†’