GATE Assistant

Past questions › Data Science and Artificial Intelligence › GATE 2026

GATE 2026 · DA · MCQ · 1 mark · 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 is the correct output of…

Consider the given Python program.

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?

  1. (A)
    [1]
    [2]
    [3]
    
  2. (B)
    [1]
    [1, 2]
    [3]
    
  3. (C)
    [1]
    [2]
    [1, 2, 3]
    
  4. (D)
    [1]
    [1, 2]
    [1, 3]
    
Show answer

This question is in an all-India live mock that is open now. Its answer appears here when the mock closes.

Practise this question with exam-style marking