Extended slice assignment edits selected positions in place. With a stride other than one, the replacement length must match the selected positions.
Worked example
values = [1, 2, 3, 4]
values[::2] = [10, 30]
print(values)Result
[10, 2, 30, 4]Implementation notes
Editing a slice updates aliased references to the same list. Assigning a new list to a local variable does not update those observers.
Try it yourself
Try an odd-length list and count the selected slots first.
Open the Python example →Editorial date June 8, 2025 · Published December 6, 2026