Python - How To Change Global Variable Within a Function (Please NEVER Do This!!!)

preview_player
Показать описание
#Python #Shorts

If we use a variable within a function that has the same name as an already defined global function, any of our manipulations will have a "local" scope and won't have any effect on the global variable. If you're crazy enough to try it and want to be miserable, make people hate you, go ahead and do the following to change the value of the global variable.
Within a function, just type "global varname" before you use it, where "varname" is the name of your global variable. And voila, you can modify the global variable in your function! Just please promise me to never actually do it, this is for educational purposes only.

-------------------------------------------------------------------------------------
Links:
Рекомендации по теме
Комментарии
Автор

I was searching for this.Thank you man👍👍

zokirgofurboyev
Автор

Why should that not be done like this?

aGuy
Автор

I want to change it in the run screen how?!

ghadasaeed
join shbcf.ru