Practice question · Select all that apply
Select every statement about scope that is true.
Hints
- Two options invert what the lesson says about locals and about globals.
- The lesson calls heavy reliance on globals a drawback, not a benefit.
Show the answer
- A. A variable declared outside all functions is global
- C. A variable created inside a function is local to that call
- D. Local scope lets two functions each use a variable named i without conflict
Why
Locals are confined to their call and vanish on return, so they cannot be read afterward; a name outside all functions is global; and local scope is exactly what lets two functions reuse the name i safely. The lesson warns that leaning on globals makes code harder to reason about, so the fifth option is false.
Practise Functions and Parameter Passing
The app has 5 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.
More questions on Functions and Parameter Passing
- Whether a function can modify its caller's argument depends on whether the argument is mutable, not on how it…
- For def scale(factor): return factor * 10, later called as scale(60), sort each item by what it is.
- Match each term to its meaning.
- A function with a default argument def f(x, items=[]) behaves strangely: the list keeps its contents between…
- Order what happens when the call y = sq(2 + 3) runs, where def sq(n): return n * n.