Chapter 3: Problem 19
What is the scope of a global variable?
Short Answer
Expert verified
Answer: The scope of a global variable is the entire program, meaning it can be accessed and modified anywhere in the code. To modify a global variable within a function, you need to declare it as global within the function using the `global` keyword, like this:
```python
global_variable = 10
def foo():
global global_variable
global_variable += 5
foo()
print(global_variable) # Output: 15
```