Class - 12 CBSE Computer Science Important Output Questions 2025
Predict the output of the following code snippet?
arr = [1, 2, 3, 4, 5, 6]
for i in range(1, 6):
arr[i - 1] = arr[i]
for i in range(0, 6):
print(arr[i], end = "")
Python
Python List Manipulation
27 Likes
Answer
234566
Working
arris initialised as a list with elements [1, 2, 3, 4, 5, 6].forloop iterates over the indices from 1 to 5. For each indexi, it assigns the value ofarr[i]toarr[i - 1], effectively shifting each element one position to the left. After this loop, the listarrbecomes[2, 3, 4, 5, 6, 6].- Second for loop iterates over the indices from 0 to 5 and prints each element of the list
arrwithout newline characters because ofend=""parameter. Then it prints the elements of the modified listarr, resulting in234566.
Answered By
11 Likes