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

Given items = [1, 2, 3, 4], what happens when items[::2] = [9] is executed?

  1. It produces [9, 2, 4].
  2. It accepts any replacement length.
  3. It raises TypeError because stepped slices are read-only.
  4. It raises ValueError because two positions need two values.پاسخ درست

توضیح

The extended slice selects two positions, but the replacement supplies only one value, so Python raises ValueError. Unlike a simple slice, a stepped assignment cannot change the number of selected slots by using a differently sized replacement.

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

شروع تمرین
سؤال 108: Given items = [1, 2, 3, 4], what happens when items[::2] =… · Python Fundamentals · Questena