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.

ادامهٔ این آزمون

شروع تمرین
سؤال 41: If `data = dict(a=1)`, what happens when `data["b"]` is… · Python Fundamentals · Questena