QuestenaPráctica que te muestra qué repasar después
Pregunta 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.Respuesta correcta
  3. `value` is 9, and both `a` and `b` become keys.
  4. The call raises `KeyError`, and the dictionary is unchanged.

Explicación

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.

Continúa con este test

Empezar la práctica
Pregunta 42: After `data = dict(a=1)` and `value = data.get("b", 9)`,… · Python Fundamentals · Questena