UnboundLocalError: cannot access local variable 'x' where it is not associated with a value

preview_player
Показать описание
If you are watching this video, you probably just got this Unbound Local error message in Python. But why does it happen and how can you fix it? In this video you learn two solutions to the problem.

C H A P T E R S
0:10 Python can access variables outside of the function
0:45 Scoping rules
1:30 The cause of an UnboundLocalError
2:40 Quick fix with the global keyword
3:25 Decouple the function to solve the problem

M Y O N L I N E T R A I N I N G

L I N K S I N T H E V I D E O

#unbound #local #error
Рекомендации по теме
Комментарии
Автор

Cannot explain how this saved my hours of research and frustration! Usually what you can get is more confusing answers and programmers bragging about their knowledge without really helping. Thank you so much. Subscribed and liked. I hope you keep it up.

DDF.
Автор

Thank you so much! I've gotten really confused with this because this error message is very misleading when you don't know why it happened.. Earned a like and sub :D

meep_poggerson
Автор

Thanks for your help! Keep making these videos, mate!

OlenaOlena-dl
Автор

Thx this was helpful, all what about def is really confusing to me
tho i take bad way 🏃‍♂🏃‍♂

hussainxLv
Автор

3:50 Of course you can also assign the result of the function call back to x.

python-for-everyone
Автор

excuse me sir, would i be able to contact you on social media to show you a problem i have regarding the unboundlocalerror?

Itzayman