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