GATE DA 2026 — Question 50

Programming, Data Structures and AlgorithmsProgramming in PythonMSQ2 marksMedium

Consider the given Python program.
python
1def outer():
2    x = []
3    def inner(val):
4        x.append(val)
5        return x
6    return inner
7f1 = outer()
8f2 = outer()
9print(f1(10)) # Line P
10print(f1(20)) # Line Q
11print(f2(30)) # Line R
12print(f1(40)) # Line S
13
Which of the following options is/are correct?
  1. A
    f1 and f2 share the same list x
  2. B
    Output of Line Q is [10, 20]
  3. C
    Output of Line R is [10, 20, 30]
  4. D
    Output of Line S is [10, 20, 40]
Practise the full 2026 paper
Challenge a friend: WhatsApp Telegram
Recommended book · affiliate linkIntroduction to Algorithms (CLRS)The standard reference behind most GATE algorithm questions.
Practise more on Programming in PythonTimed, in the real exam interface · free to start

A GATE question every morning

One real past-paper question every morning for your branch, answer hidden until you tap. Free on Telegram.

Join
Stuck? Ask in the student group