Questenaتمرینی که نشان می‌دهد بعد چه چیزی را مرور کنید
سؤال 28

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

  1. It changes the list to `["a", "x", "b"]`.پاسخ درست
  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.

توضیح

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.

ادامهٔ این آزمون

شروع تمرین
سؤال 28: What does `items.insert(1, "x")` do when `items` is `["a",… · Python Fundamentals · Questena