What is the output of the following code ?
s1 = [23, 45, 61, 12, 31, 91, 23] for i in range(1, 7): s1[i - 1] = s1[i] for i in range(0, 7): print(s1[i], end=" ")
23 45 61 12 31 91 23 23
45 61 12 31 91 23 23
45 61 12 31 91 23
45 61 12 31 91
s1[i - 1] = s1[i] will shift each element to left
For example in the first iteration , s[0] = s1[1], the value in s1[1] will be assigned to s1[0].
So the result will be 45 61 12 31 91 23 23
Comment here: