Skip to content
Exercises · Q4

Q.What will be the output of the following code segment?

a) myList = [1,2,3,4,5,6,7,8,9,10]
del myList[3:]
print(myList)
b) myList = [1,2,3,4,5,6,7,8,9,10]
del myList[:5]
print(myList)
c) myList = [1,2,3,4,5,6,7,8,9,10]
del myList[::2]
print(myList)
Uttarakhand UbseTextbookSubjective· 3mImportance★★★★★est
40% · 12/30 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

del with a slice removes every element the slice selects, in place: del myList[3:] keeps the first three → [1, 2, 3]; del myList[:5] drops the first five → [6, 7, 8, 9, 10]; del myList[::2] deletes the elements at even indexes → [2, 4, 6, 8, 10].

Each part restarts from myList = [1,2,3,4,5,6,7,8,9,10].

a) del myList[3:] — delete from index 3 to the end

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

The slice [3:] selects indexes 3…9 (values 4…10); del removes exactly those, keeping indexes 0, 1, 2.

b) del myList[:5] — delete from the start up to (not including) index 5

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

[:5] selects indexes 0…4 (values 1…5). The stop index 5 is excluded from the slice, so element 6 (at index 5) survives.

c) del myList[::2] — delete every second element starting at index 0

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

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.