QuestenaUn entraînement qui indique quoi revoir ensuite
Question 29

A list is `[4, 2, 4]`. Which description of `items.remove(4)` is correct if `items` refers to that list?

  1. It deletes both occurrences and leaves `[2]`.
  2. It deletes the first matching value and leaves `[2, 4]`.Bonne réponse
  3. It deletes the element at index 4.
  4. It ignores a missing value without an exception.

Explication

The method searches by equality and deletes only the earliest matching element, leaving `[2, 4]`. It does not interpret 4 as an index or remove every duplicate, and absence would produce `ValueError` rather than a silent no-op.

Continuer avec ce test

Commencer l’entraînement
Question 29: A list is `[4, 2, 4]`. Which description of… · Python Fundamentals · Questena