Questenaتدريب يوضح لك ما ينبغي مراجعته لاحقًا
السؤال 41

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

  1. It raises `KeyError`.الإجابة الصحيحة
  2. It returns `None`.
  3. It inserts `b` with value `None`.
  4. It returns an empty dictionary.

الشرح

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.

تابع هذا الاختبار

بدء التدريب