KnowledgeBoat Logo
|
LoginJOIN NOW

Informatics Practices

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)

Python List Manipulation

1 Like

Answer

[6, 7, 8, 9, 10]

Working

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].

Answered By

1 Like


Related Questions