Why does this UnboundLocalError occur (closure)? [duplicate]

What am I doing wrong here?

counter = 0

def increment():
  counter += 1

increment()

The above code throws an UnboundLocalError.

8 Answers
8

Leave a Comment