Can not increment global variable from function in python [duplicate]

Use a global statement, like so:

COUNT = 0

def increment():
    global COUNT
    COUNT = COUNT+1

increment()

Global variables can be accessed without using global, but the statement is required in order to change the value of the global variable.

Leave a Comment