Correct answer: (B) Three lines: [1], then [1, 2], then [3]
Explanation
A default argument is evaluated once, when the function is defined, so every call that does not pass a list shares the same default list. The first call appends 1 to it and prints [1]. The second call appends 2 to the same list and prints [1, 2]. The third call passes a new empty list, so it prints [3].
More Programming in Python questions
GATE 2026 DA Q39– A recursive function in Python is given. Now, consider the following function call: Assume…
GATE 2026 DA Q50– Consider the given Python program. Which of the following options is/are correct?
GATE 2026 DA Q58– Consider the given Python program. The output of the program is . (*Answer in integer*)
GATE 2025 DA Q23– Consider the following Python declarations of two lists. Which one of the following…
GATE 2025 DA Q47– Consider the following Python code snippet. When the above program is executed, at the…
GATE 2025 DA Q63– Consider the following Python code snippet. The value printed by the code snippet is…