Certified Entry-Level Python Programmer (PCEP-30-02) — Question 33
A variable defined outside a function:
Answer options
- A. may be read, but not written (something more is needed to do so)
- B. may not be accessed in any way inside the function
- C. may be freely accessed inside the function
Correct answer: A
Explanation
The correct answer is A because a variable defined outside a function can be read inside the function but requires additional mechanisms, like using the 'global' keyword, to modify it. Option B is incorrect as variables defined outside are not completely inaccessible; they can be read. Option C is also wrong since while the variable can be accessed, it cannot be freely modified without explicit permission.