GATE DA 2026, Q.50: Each outer() call makes its own list
The question
For the code below, which are true? (A) f1 and f2 share the same list x. (B) Line Q prints [10, 20]. (C) Line R prints [10, 20, 30]. (D) Line S prints [10, 20, 40].
def outer():
x = []
def inner(val):
x.append(val)
return x
return inner
f1 = outer()
f2 = outer()
print(f1(10)) # Line P
print(f1(20)) # Line Q
print(f2(30)) # Line R
print(f1(40)) # Line S- (A) f1 and f2 share the same list x
- (B) Output of Line Q is [10, 20]
- (C) Output of Line R is [10, 20, 30]
- (D) Output of Line S is [10, 20, 40]
Watch it solved
Solve it step by step
- Closures. Each call of outer() creates a new x and returns an inner function that remembers it.
- f1. f1(10) → [10], f1(20) → [10, 20] (B true).
- f2. f2 has its own list: f2(30) → [30] (A and C false).
- Back to f1. f1(40) → [10, 20, 40] (D true).
Answer: B, D
Official IIT Guwahati answer key: B; D.
Common mistake. Treating x like a global or a mutable default shared by everyone.
Remember. A closure captures the variables of the call that created it.
Want every question solved? The past-paper pack has all 195 questions from 2024, 2025 and 2026 for ₹499. The cheat sheet pack has 23 printable sheets for ₹399.
See the past-paper pack See the cheat sheetsSource: official GATE DA 2026 question paper and answer key (IIT Guwahati). The question is lightly reworded; every number and option is kept.