GATE Assistant

Past questions › Data Science and Artificial Intelligence › GATE 2026

GATE 2026 · DA · MSQ · 2 marks · Programming, Data Structures and Algorithms › Python Programming

GATE 2026 Data Science and Artificial Intelligence question: Consider the given Python program. code Which of the following options is/are correct?

Consider the given Python program.

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?

  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]

Show answer

Official answer: B,D

Practise this question with exam-style marking

Discussion

No discussion yet.

Join the discussion