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?

d = {'a': 1, 'b': 2}
print(d.popitem())
  1. ('a', 1)
  2. b
  3. ('b', 2) Correct answer
  4. Error

Correct answer

C. ('b', 2)

MCQSEXAM

Explanation

popitem() removes and returns the last inserted item (LIFO) in Python 3.7+.

Reference

Asked in: Python Interview Dictionaries

https://docs.python.org/3/tutorial/datastructures.html#dictionaries

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