👻 Check our latest review to choose the best laptop for Machine Learning engineers and Deep learning tasks!
The following code gives the error UnboundLocalError: local variable "Var1" referenced before assignment
:
Var1 = 1
Var2 = 0
def function():
if Var2 == 0 and Var1 > 0:
print("Result One")
elif Var2 == 1 and Var1 > 0:
print("Result Two")
elif Var1 < 1:
print("Result Three")
Var1 =- 1
function()
How can I fix this? Thanks for any help!
👻 Read also: what is the best laptop for engineering students?
We hope this article has helped you to resolve the problem. Apart from Python 3: UnboundLocalError: local variable referenced before assignment, check other code Python module-related topics.
Want to excel in Python? See our review of the best Python online courses 2023. If you are interested in Data Science, check also how to learn programming in R.
By the way, this material is also available in other languages:
- Italiano Python 3: UnboundLocalError: local variable referenced before assignment
- Deutsch Python 3: UnboundLocalError: local variable referenced before assignment
- Français Python 3: UnboundLocalError: local variable referenced before assignment
- Español Python 3: UnboundLocalError: local variable referenced before assignment
- Türk Python 3: UnboundLocalError: local variable referenced before assignment
- Русский Python 3: UnboundLocalError: local variable referenced before assignment
- Português Python 3: UnboundLocalError: local variable referenced before assignment
- Polski Python 3: UnboundLocalError: local variable referenced before assignment
- Nederlandse Python 3: UnboundLocalError: local variable referenced before assignment
- 中文 Python 3: UnboundLocalError: local variable referenced before assignment
- 한국어 Python 3: UnboundLocalError: local variable referenced before assignment
- 日本語 Python 3: UnboundLocalError: local variable referenced before assignment
- हिन्दी Python 3: UnboundLocalError: local variable referenced before assignment
Munchen | 2023-02-08
Thanks for explaining! I was stuck with Python 3: UnboundLocalError: local variable referenced before assignment for some hours, finally got it done 🤗. I just hope that will not emerge anymore
Moscow | 2023-02-08
Thanks for explaining! I was stuck with Python 3: UnboundLocalError: local variable referenced before assignment for some hours, finally got it done 🤗. I am just not quite sure it is the best method
Paris | 2023-02-08
Simply put and clear. Thank you for sharing. Python 3: UnboundLocalError: local variable referenced before assignment and other issues with code Python module was always my weak point 😁. I just hope that will not emerge anymore