KnowledgeBoat Logo

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

11 Likes

Answer

234566

Working

  1. arr is initialised as a list with elements [1, 2, 3, 4, 5, 6].
  2. for loop iterates over the indices from 1 to 5. For each index i, it assigns the value of arr[i] to arr[i - 1], effectively shifting each element one position to the left. After this loop, the list arr becomes [2, 3, 4, 5, 6, 6].
  3. Second for loop iterates over the indices from 0 to 5 and prints each element of the list arr without newline characters because of end="" parameter. Then it prints the elements of the modified list arr, resulting in 234566.

Answered By

4 Likes