# 04 · nonlocal-counter **演示**:闭包共享同一个局部变量;`nonlocal` 让内层函数修改外层的 `count`。 **运行**: ```sh uv run python examples/06-functions-closures/04-nonlocal-counter/nonlocal_counter.py ``` **预期输出**(3.12.9): ```text after +5: 15 after +1: 16 get: 16 ``` **依赖**:仅标准库。 **注意**:不用 `nonlocal` 时,`count += 1` 会被判定为局部变量,抛 `UnboundLocalError`。