Advertisements
Advertisements
Question
What will be the output of the following code segment:
myList = [1,2,3,4,5,6,7,8,9,10]
del myList[::2]
print(myList)Short/Brief Note
Advertisements
Solution
The statement in line 2 will delete the elements from the start to the end of the list with step size 2. i.e it will delete elements starting from index 0, then index 2, index 4, index 6 … and so on. The output will be the remaining elements i.e. [2, 4, 6, 8, 10].
shaalaa.com
Lists Manipulation in Python
Is there an error in this question or solution?
