๐ŸŽ 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

Celery
A distributed task queue for Python that enables asynchronous processing of background jobs and scheduled tasks.
Virtual Environment
An isolated Python environment that maintains its own set of packages, independent of the system Python installation.
Exception Handling
A mechanism for managing runtime errors using try, except, else, and finally blocks to prevent program crashes.
Python Context Variable
A variable that maintains separate values for each execution context, enabling implicit state passing in async code without global variables.
Asyncio
A Python library for writing concurrent code using async/await syntax for non-blocking I/O operations.
Python Metaclass
A class whose instances are classes themselves โ€” the class of a class that controls how classes are created and behaved.
View All Python Terms โ†’