QuestenaPractice that shows what to review next
Question 28

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

  1. It changes the list to `["a", "x", "b"]`.Correct answer
  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.

Explanation

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.

Continue with this test

Start practice
Question 28: What does `items.insert(1, "x")` do when `items` is `["a",… · Python Fundamentals · Questena