UnboundLocalError: local variable ‘…’ referenced before assignment
Problem: an error occurs when the code looks like:
x = 23
def f():
print(x)
x = 42
f()
Solution: use global
or nonlocal
.
UnboundLocalError: local variable ‘…’ referenced before assignment
Problem: an error occurs when the code looks like:
x = 23
def f():
print(x)
x = 42
f()
Solution: use global
or nonlocal
.