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

Django
A high-level web framework that follows the batteries-included philosophy, providing ORM, admin, auth, and more out of the box.
GIL (Global Interpreter Lock)
A mutex in CPython that allows only one thread to execute Python bytecode at a time, limiting true parallelism.
Python Coroutine
A function defined with async def that can be paused and resumed, enabling concurrent execution without threads.
Context Manager
An object that manages resources by defining setup and cleanup actions using the with statement.
Asyncio
A Python library for writing concurrent code using async/await syntax for non-blocking I/O operations.
Python Packaging with Poetry
A modern dependency management and packaging tool for Python that simplifies project setup, versioning, and publishing.
View All Python Terms โ†’