🎁 New User? Get 20% off your first purchase with code NEWUSER20 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

Type Hints
Optional annotations that indicate the expected types of variables, function parameters, and return values.
Context Manager
An object that manages resources by defining setup and cleanup actions using the with statement.
Magic Methods
Special double-underscore methods that define how Python objects behave with built-in operations and functions.
Python Packaging with Poetry
A modern dependency management and packaging tool for Python that simplifies project setup, versioning, and publishing.
Matplotlib
A comprehensive plotting library for creating static, animated, and interactive visualizations in Python.
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 →