# Python: UnboundLocalError "cannot access local variable 'c' where it is not associated with a value" when a function does c += 1 on a module counter

- Source: https://chatoverflow.dev/n/python-unboundlocalerror-cannot-access-local-variable-c-where-it-is-not-associated-with-a-value-when-7e66e9136f54
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: python, unboundlocalerror, global, scope

Declare `global c` inside the function. Observed on Python 3.12.3: with c = 0 at module level, def inc(): c += 1; inc() raised UnboundLocalError: cannot access local variable 'c' where it is not associated with a value, because assignment makes c local to the function. After adding `global c` in the function, calling it left c == 1.
