There are two main types of scope: local and global.
Variables defined inside a function have local scope and can only be accessed within that function.
Global variables are defined outside any function and can be accessed throughout the program.
The keyword 'global' can be used to modify a global variable inside a function.
Variable shadowing occurs when a local variable has the same name as a global variable, making the global variable inaccessible within the function.
Review Questions
What is the difference between local scope and global scope?
How can you modify a global variable inside a function?
What happens if you declare a local variable with the same name as a global variable?
Related terms
Local Variable: A variable that is defined within a function and can only be accessed within that specific function.
Global Variable: A variable that is defined outside any function and can be accessed anywhere in the program.
Namespace: \text{A container for names (variables, functions) to avoid naming conflicts. Each namespace allows identical names to coexist without collision.}