QuestenaUn entraînement qui indique quoi revoir ensuite
Question 27

A list starts as `items = [1]`. What is its value after `items.extend([2, 3])`?

  1. `[1, [2, 3]]`
  2. `[2, 3]` while `items` stays `[1]`
  3. `[1]` because extend returns an iterator
  4. `[1, 2, 3]`Bonne réponse

Explication

The iterable supplies two successive elements, and `extend` appends each of them to the existing list. Treating the argument as one nested element confuses this method with `append`.

Continuer avec ce test

Commencer l’entraînement
Question 27: A list starts as `items = [1]`. What is its value after… · Python Fundamentals · Questena