1. Home
  2. Data Science
  3. Python
  4. What is the output of print(dict.fromkeys(['a', 'b'])) in…

Added 25 Nov 2026

What is the output of print(dict.fromkeys(['a', 'b'])) in Python?

print(dict.fromkeys(['a', 'b']))
  1. {'a': 0, 'b': 0}
  2. ['a', 'b']
  3. Error
  4. {'a': None, 'b': None} Correct answer

Correct answer

D. {'a': None, 'b': None}

6 views

MCQSEXAM

Explanation

dict.fromkeys sets the same value for all keys, default None.

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