QuestenaՎարժանք, որը ցույց է տալիս՝ ինչ կրկնել հաջորդիվ
Հարց 45

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

  1. It raises `KeyError`.Ճիշտ պատասխան
  2. It leaves the dictionary unchanged without an exception.
  3. It inserts `b` with value `None`.
  4. It clears the entire dictionary.

Բացատրություն

Deletion by key requires an existing entry, and this dictionary has no key `b`, so Python raises `KeyError`. The operation is not silently ignored and does not create a key whose value is `None`.

Շարունակեք այս թեստով

Սկսել վարժանքը
Հարց 45: If `data = dict(a=1)`, what happens when `del data["b"]`… · Python Fundamentals · Questena