GATE DA 2026 | Question 50
Programming, Data Structures and Algorithms › Python Programming · MSQ · 2 marks · Answer: B, D
- Question 50Programming, Data Structures and Algorithmsmsq2 marksConsider the given Python program.
Which of the following options is/are correct?pythondef 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]✓
Answer: B, D
Solution
Each call toouter()creates a new listx, and the returnedinnerkeeps (closes over) its ownx. Sof1andf2have separate lists. - Line P:f1list is[10]- Line Q:[10, 20]- Line R:f2list is[30]- Line S:f1list is[10, 20, 40]Answer: (B), (D). - A.
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 →