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

its a global variable so do this :

COUNT = 0

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

increment()

print COUNT

Global variables can be accessed without declaring the global but if you are going to change their values the global declaration is required.

Leave a Comment