QuestenaPractice that shows what to review next
Question 41

If `data = dict(a=1)`, what happens when `data["b"]` is evaluated?

  1. It raises `KeyError`.Correct answer
  2. It returns `None`.
  3. It inserts `b` with value `None`.
  4. It returns an empty dictionary.

Explanation

Subscription requires the requested key to exist, and `b` has no mapping in this dictionary, so lookup raises `KeyError`. It neither returns `None` nor inserts a default entry as a side effect.

Continue with this test

Start practice
Question 41: If `data = dict(a=1)`, what happens when `data["b"]` is… · Python Fundamentals · Questena