I have a list s
which looks as below:
s = list(range(1, 11))
I am replacing slice of 's'
using below code:
s[1:4] = [0, 0, 0, 0]
print(s)
Output: [1, 0, 0, 0, 0, 5, 6, 7, 8, 9, 10]
However, when trying to assign the same list [0, 0, 0, 0]
to an extended slice of 's'
, then the interpreter is throwing an error.
s[1:4:2] = [0, 0, 0, 0]
ValueError: attempt to assign sequence of size 4 to extended slice of size 2
I want to understand why python didn't throw an error with s[1:4] = [0, 0, 0, 0]
because even in that case we are attempting to assign sequence of size 4 to slice of size 3?