Our teacher is telling us to use it for the coursework but i dotn understand what the function of global ( name) is?
Turn on thread page Beta
Python - whats the purpose of global variable watch
- Thread Starter
- 24-01-2017 18:59
- 24-01-2017 21:49
Really? My teacher said that using global variable makes you loose marks.
A global variable is essentially a variable that is accessible throughout the program (not just in one variable).
- 24-01-2017 22:23
Generally most people say not to use global variables but depending on the task, they may be more efficient.
Local variable is something that only is accessible in one function. While global can be used through out. So
a = "hello"
b = "world"
Run example() and result will be "hello" "world"
Run example2() and you'll get "hello" and then an error for non existent variable because it's only available in example()