ProgrammingEasyTCS NQT · Infosys pattern

What is printed?

What is printed?
d = {"a": 1}
print(d.get("b", 0), "a" in d, 1 in d, d.get("b"))
  1. A. 0 True False None
  2. B. 0 True True None
  3. C. None True False 0
  4. D. 0 True False KeyError

Correct answer: A. 0 True False None

get returns the default (0) for a missing key, or None when no default is given; it never raises KeyError. The in operator on a dict checks KEYS, so "a" in d is True and 1 in d is False even though 1 is a value.

More Python Programming questions

Exams that ask this topic