ProgrammingHardCognizant GenC · TCS NQT

What is printed?

What is printed?
d = {'a': {'b': 1}}
print(d.get('a', {}).get('c', 0), d.get('x', {}).get('b'), d['a'].get('b'))
  1. A. 0 0 1
  2. B. 0 None 1
  3. C. 0 None 0
  4. D. None None 1

Correct answer: B. 0 None 1

Each get on an inner dict uses a default. The missing outer key x falls back to an empty dict, so its get returns None, while key b in a is 1.

More Python Programming questions

Exams that ask this topic