What are the rules for a local and global variable?
Answer»
Variables at the Global Level:
Global variables are variables declared outside of a function or in a global space.
If a VARIABLE is ever given a new value within the function, it is implicitly local, and we must EXPLICITLY declare it as 'global.' We must declare a variable USING the global keyword to make it global.
Any function can ACCESS and modify the value of global variables from anywhere in the programme.
Variables in the Local Environment:
A local variable is any variable declared within a function. This variable exists only in local space, not in global space.
It's PRESUMED that a variable is local if it gets a new value anywhere in the function's body.
Only the local body has access to local variables.