Gradient LabSign up free

Home / GATE DA / 2026 / Q.50

GATE DA 2026, Q.50: Each outer() call makes its own list

ProgrammingPython closures2 marksMSQ (more than one correct)Free

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

Watch it solved

Solve it step by step

  1. Closures. Each call of outer() creates a new x and returns an inner function that remembers it.
  2. f1. f1(10) → [10], f1(20) → [10, 20] (B true).
  3. f2. f2 has its own list: f2(30) → [30] (A and C false).
  4. 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 sheets

Source: official GATE DA 2026 question paper and answer key (IIT Guwahati). The question is lightly reworded; every number and option is kept.