Questenaتدريب يوضح لك ما ينبغي مراجعته لاحقًا
السؤال 107

After items = [1, 2, 3, 4] and items[1:3] = [8, 9, 10], which statement is correct?

  1. The length stays 4 because slice assignment cannot resize.
  2. A new six-item list is created without changing items.
  3. The list is changed in place and its length becomes 5.الإجابة الصحيحة
  4. It raises ValueError because the lengths must match.

الشرح

The simple slice selects two positions but receives three replacement values, so the list grows by one and its length becomes five. Ordinary slice assignment may resize a list; equal replacement length is not required.

تابع هذا الاختبار

بدء التدريب
السؤال 107: After items = [1, 2, 3, 4] and items[1:3] = [8, 9, 10],… · Python Fundamentals · Questena