GATE DA 2026 | Question 50

Programming, Data Structures and Algorithms › Python Programming · MSQ · 2 marks · Answer: B, D

  1. Question 50Programming, Data Structures and Algorithmsmsq2 marks
    Consider the given Python program.
    python
    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
    Which of the following options is/are correct?
    • 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]
      ✓

    Answer: B, D

    Solution

    Each call to outer() creates a new list x, and the returned inner keeps (closes over) its own x. So f1 and f2 have separate lists. - Line P: f1 list is [10] - Line Q: [10, 20] - Line R: f2 list is [30] - Line S: f1 list is [10, 20, 40] Answer: (B), (D).

More GATE PYQ on Python Programming

All GATE DA Programming, Data Structures and Algorithms PYQ →

Attempt GATE DA 2026 in real GATE exam mode

Full paper with a timer, the GATE interface and a topic-wise analysis — free.

Create free account →