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