+ 1

global

What does global do? I keep seeing: global *something here* I want to know what the point is for this funtion

8th Aug 2018, 5:30 AM
Hayden
2 Respostas
+ 19
"""a variable declared outside of the function or in global scope is known as global variable... global variable can be accessed inside and outside of function... example : """ x = 10 #x is global def func(): x = x*2 print(x) func() #👆this code will cause error #because local variable "x" is not declared inside function.... #to use the outside value of x inside func() #u need to do... x = 10 def func(): global x x = x*2 print(x) func() #I hope this is what u were asking.. :)
8th Aug 2018, 5:44 AM
🌛DT🌜
🌛DT🌜 - avatar
0
Oooohhhhhh, I saw a game code that used def and global a lot. I'm building an A.I right now and when I test certain parts it wouldn't work because something was not defined but it was defined before but in a func
8th Aug 2018, 5:50 AM
Hayden