Variable Scope
Variable Scope
The scope of a variable is where you can access it.
One way to think about the scope of a variable is where it lives and who can see it in a program.
Global Variable
A global variable is defined outside of functions and is visible to all functions that are defined after it.
scope.py
What is the output of this program?
Local Variable
A local variable is defined within a function. Another way to think about it is, a variable that is declared inside a function, stays inside the function.
What is the output of this program?
Local vs Global Variable
What is the output of this program?
Last updated