'How can i understand Python about list. help me please [duplicate]
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?
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | BrokenBenchmark |
