-2
score = [88,95,70,100,99,80,78,50]
score[1:4]=[]
print(score) 

I expected this code snippet to print [95,70,100]. Instead, it printed out [88, 99, 80, 78, 50]. Why is this so?

BrokenBenchmark
  • 18,126
  • 7
  • 21
  • 33
  • According to you code at line two you remove indices 1,2,3 from list score. So it remove 95 70 and 100 from list. For printing 95 70 100 the code should be score=score[1:4] – M. Twarog Feb 01 '22 at 06:32

1 Answers1

0

On the second line, the code takes a list slice and then sets it to the empty list, effectively removing them from the original score list.

The following line prints the score list, with items originally at indices 1, 2, and 3 removed. You're mixing up the items remaining in the score list with the ones that were just removed.

BrokenBenchmark
  • 18,126
  • 7
  • 21
  • 33