CBSE Class 11 Informatics Practices Question 51 of 80

Lists in Python — Question 14

Back to all questions
14
Question

Question 10(b)

What will be the output of the following code segment?

myList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
del myList[:5]
print(myList)
Answer
Output
[6, 7, 8, 9, 10]
Explanation

In the given code, myList is initialized as [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]. The del myList[:5] statement deletes all elements in the list from the beginning up to, but not including, index 5. This removes the first five elements (1, 2, 3, 4, 5) from myList. The subsequent print(myList) statement then outputs the modified list, which is [6, 7, 8, 9, 10].