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