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

Exception Handling
A mechanism for managing runtime errors using try, except, else, and finally blocks to prevent program crashes.
Python Descriptors
Objects that define __get__, __set__, or __delete__ methods, controlling how attribute access works on other objects.
Type Hints
Optional annotations that indicate the expected types of variables, function parameters, and return values.
Pydantic
A data validation library that uses Python type annotations to validate and serialize data with automatic error reporting.
F-String
A formatted string literal prefixed with f that allows embedding Python expressions directly inside curly braces.
NumPy
A fundamental library for numerical computing in Python, providing efficient multi-dimensional arrays and mathematical operations.
View All Python Terms โ†’