1. What is a 'local variable' in Python?
2. What is a 'global variable' in Python?
3. Consider the following code:
message = "Hello" def greet(): message = "Hi" print(message) greet() print(message)
4. Where can a variable defined *inside* a function (without using `global`) be accessed?
5. Why is understanding scope important in programming?
6. If a function needs to modify a global variable, what keyword might it need to use *inside* the function before assigning a new value to that variable?
7. Consider this code:
count = 0 def increment(): count = count + 1 # Attempts to modify 'count' print(count) increment()
8. Can a function access a global variable without using the `global` keyword?
9. What is the scope of a variable defined in a `for` loop statement (like `i` in `for i in range(5):`) within a function?
10. If you define a variable inside a function, and then the function finishes executing, what happens to that local variable?