๐ŸŽ 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 Wheel
A built distribution format (.whl) that allows faster installation of Python packages by avoiding the need for compilation.
GIL (Global Interpreter Lock)
A mutex in CPython that allows only one thread to execute Python bytecode at a time, limiting true parallelism.
ABC (Abstract Base Class)
A class that defines a common interface for subclasses by declaring abstract methods that must be implemented.
Python ABC Module
The Abstract Base Classes module that enables defining interfaces and abstract methods that subclasses must implement.
Module
A Python file containing definitions and statements that can be imported and reused in other Python programs.
Decorator
A function that modifies or extends the behavior of another function or class without changing its source code.
View All Python Terms โ†’