> For the complete documentation index, see [llms.txt](https://ret2basic.gitbook.io/ctfnote/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ret2basic.gitbook.io/ctfnote/computer-science/python/generators.md).

# Generators

## Generators and `yield`

{% hint style="info" %}
If a function uses the `yield` keyword, it defines an object known as a **generator.**
{% endhint %}

The primary use of a generator is to produce values for use in iteration. Here's an example:

```python
def countdown(n):
    print('Counting down from', n)
    while n > 0:
        yield n
        n -= 1

# Example use
from x in countdown(10):
    print('T-minus', x)
```

## Restartable Generators

## Generator Delegation

## Using Generators in Practice

## Enhanced Generators and `yield` Expressions

## Applications of Enhanced Generators

## Generators and the Bridge to Awaiting
