+ 1
I don't understand global variable
The title says it all, I don't understand global variable. How can I use them? When is it better to use them?.Why ppl say it's dangerous using global variable?. examples?
2 Respostas
+ 2
A global variable is a variable that isn't locked to the scope of a method. For example lets say that you have a method named Foo and a class named Testing.
if you define a variable in the class but outside a method at the top if the document.
(I don't remember if python interprets fields in order from top down) then that variable us global to that class, other methods may call and modify thus variable. If perhaps you have that method "Foo" and you define a variable in it then it is restricted to that method unless you declare it global.
Variables defined at class level are by default global.
Variables defined at method level are by default local unless declared global.
0
Ty