QuestenaÜben und erkennen, was als Nächstes dran ist
Frage 28

What does `items.insert(1, "x")` do when `items` is `["a", "b"]`?

  1. It changes the list to `["a", "x", "b"]`.Richtige Antwort
  2. It changes the list to `["a", "b", "x"]`.
  3. It replaces `"b"` and leaves two elements.
  4. It raises IndexError because index 1 is occupied.

Erklärung

Insertion at index 1 places the new value before the element that was at that index, producing `a`, `x`, `b` in order. It does not replace `b`, because slice or indexed assignment would be needed for replacement.

Mit diesem Test weitermachen

Übung starten
Frage 28: What does `items.insert(1, "x")` do when `items` is `["a",… · Python Fundamentals · Questena