1. Home
  2. Data Science
  3. Python
  4. What is the output of print({'a': 1, 'b': 2}.keys()…

Added 25 Nov 2026

What is the output of print({'a': 1, 'b': 2}.keys() - {'a': 0}.keys()) in Python?

print({'a': 1, 'b': 2}.keys() - {'a': 0}.keys())
  1. {'b'} Correct answer
  2. {'a'}
  3. {'a', 'b'}
  4. Error

Correct answer

A. {'b'}

10 views

MCQSEXAM

Explanation

Subtracting key views gives the keys unique to the first dictionary.

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