# nonlocal

say it: **“non-LOH-kul”** **/ˌnɑnˈloʊkəl/**

Lets an inner function change a variable from the function around it.

## What does `nonlocal` do?

`nonlocal` lets an inner function change a variable that belongs to the function around it, instead of making a new local one.

```python
def make_counter():
    count = 0
    def click():
        nonlocal count
        count += 1
        return count
    return click

counter = make_counter()
counter(); print(counter())  # 2
```

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/nonlocal
