Skip to content
GATEiit

GATE DA 2026 Q16: Python mutable default argument output

Question

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? (Each option lists the three printed lines.)

Try it: multiple choice: exactly one correct option

Select one option
Wrong answer costs 1/3 mark in GATE.
Show answer and explanation

Answer: B (official GATE 2026 final answer key)

Concept used: A default argument is created once, when the function is defined, and shared by every call that uses it.

First step: The first two calls append to the same default list; the third call passes a new empty list.

Full step-by-step solution

Detailed working, common mistakes and linked mock tests will be available with a free GATEiit account. Log-in is coming soon.

Share this question

WhatsAppDownload image

Source: official GATE 2026 DA question paper and final answer key, organised by IIT Guwahati. Question paper · Answer key