ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
d = {"a": 1}
v = d.values()
k = d.keys()
d["b"] = 2
print(list(v), k - {"a"}, "b" in k)
  1. A. [1, 2] {'b'} True
  2. B. [1] set() False
  3. C. [1, 2] {'a', 'b'} True
  4. D. [1] {'b'} True

Correct answer: A. [1, 2] {'b'} True

keys() and values() return live views that reflect later changes to the dict. Key views also support set operations, so k - {'a'} is {'b'}.

More Python Programming questions

Exams that ask this topic