[Python] UnboundLocalError (Variable Scope inside a Function)
- 2023.07.22
- global Python Variable Scope
- UnboundLocalError
lst = [1, 2, 3] def foo(): lst.append(5) # OK lst += [5] # ERROR here foo() lst += [5]≡lst = lst + [5] In Python, variables that are only referenced inside a function are implicitly global. If a varia ...