What is global and local variables | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What is global and local variables

30th Nov 2016, 7:34 AM
Rakesh
Rakesh - avatar
2 Answers
+ 4
https://code.sololearn.com/c5a3zTNVrnyW/#py Lessons: - Variables declared outside functions can be read in functions (they're globally-available), unless the function sets a variable by the same name...making that name local to the function (note the Exception). - To set the global variable (which would otherwise immediately be local) you must declare your intention to set it with the word 'global'.
30th Nov 2016, 8:12 AM
Kirk Schafer
Kirk Schafer - avatar
+ 1
Simply: A global variable is a variable that can be accessed anywhere in the code - any function etc. A local variable is a variable that is 'exclusive' to that specific function, and can only be accessed within it- unless the value is returned... HOPE THIS HELPS!
8th Jan 2017, 8:34 AM
Ethan
Ethan - avatar