# Generator

say it: **“JEN-uh-ray-ter”** **/ˈdʒɛnəreɪtər/**

A function that hands out values one at a time with yield.

## What is a **generator**?

A **generator** is a function that hands out values one at a time with `yield`, only when asked. It never builds the whole list, so it can work through huge amounts of data using very little memory.

```python
def ticket_numbers(start):
    number = start
    while True:
        yield number
        number += 1

tickets = ticket_numbers(100)
print(next(tickets), next(tickets))  # 100 101
```

Level: Freelancer · [More Python terms at this level](https://www.ask-codey.com/glossary?category=python&level=4)

Updated: November 17, 2026

Source: https://www.ask-codey.com/glossary/generator
