Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

readme.md

UnboundLocalError: local variable referenced before assignment

Reproduce

count = 10

def update():
    count = count + 1

update()

Error Message

UnboundLocalError: local variable 'count' referenced before assignment

Fix

count = 10

def update():
    global count
    count = count + 1

update()
print(count)

Reflection

I tried to update a variable inside a function without declaring it.