1. Home
  2. Data Science
  3. Python
  4. What is the output of the following Python code snippet?

Added 25 Nov 2026

What is the output of the following Python code snippet?

def f(x, lst=[]):
lst.append(x)
return lst
f(1)
print(f(2))
  1. [2]
  2. [1]
  3. [1, 2] Correct answer
  4. None

Correct answer

C. [1, 2]

9 views

MCQSEXAM

Explanation

The default list is created once at definition time, so both calls append to the same list.

Reference

Asked in: Python Interview Functions

https://docs.python.org/3/tutorial/controlflow.html#defining-functions

Preparing for an exam?

Doubts & discussion

Not sure why the answer is C? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Python MCQs

Practise all Python MCQs

Similar MCQs