1. Home
  2. Data Science
  3. Python
  4. What is the recommended way to avoid the mutable default…

Added 25 Nov 2026

What is the recommended way to avoid the mutable default argument pitfall in Python?

  1. Use None as the default and create the list inside the function Correct answer
  2. Use a global list
  3. Use tuple unpacking
  4. Use eval()

Correct answer

A. Use None as the default and create the list inside the function

5 views

MCQSEXAM

Explanation

Setting lst=None and creating a new list inside the function avoids shared state.

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 A? 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