Questenaتمرینی که نشان می‌دهد بعد چه چیزی را مرور کنید
سؤال 42

After `data = dict(a=1)` and `value = data.get("b", 9)`, what are `value` and the keys of `data`?

  1. `value` is `None`, and only `a` remains a key.
  2. `value` is 9, and only `a` remains a key.پاسخ درست
  3. `value` is 9, and both `a` and `b` become keys.
  4. The call raises `KeyError`, and the dictionary is unchanged.

توضیح

Because `b` is absent, `get` returns the supplied default 9, but it performs no assignment to the dictionary. Expecting a new key confuses a nonmutating lookup with methods that explicitly create missing entries.

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

شروع تمرین
سؤال 42: After `data = dict(a=1)` and `value = data.get("b", 9)`,… · Python Fundamentals · Questena