GATE DA 2026 | Question 16

Programming, Data Structures and Algorithms › Python Programming · MCQ · 1 mark · Answer: B

  1. Question 16Programming, Data Structures and Algorithmsmcq1 mark
    Consider the given Python program.
    python
    def append_to_lst(val, lst=[]): lst.append(val) return lst print(append_to_lst(1)) print(append_to_lst(2)) print(append_to_lst(3, []))
    Which of the following is the correct output of this program?
    • A.
      [1]
      [2]
      [3]
    • B.
      [1]
      [1, 2]
      [3]
      ✓
    • C.
      [1]
      [2]
      [1, 2, 3]
    • D.
      [1]
      [1, 2]
      [1, 3]

    Answer: B

    Solution

    A default argument value is created once, when the function is defined, and the same list object is reused on every call that does not pass lst. - append_to_lst(1): the default list becomes [1]. - append_to_lst(2): the same default list becomes [1, 2]. - append_to_lst(3, []): a new empty list is passed, so the result is [3]. Answer: (B).

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 →