+ 1
Please explain this code
Hello. Please explain the second line: list = [0,1,2,3,4,5] print(list[:1:-1][1])
2 Respuestas
+ 2
list[:1] would mean the list up to (but not including) index 1.
However,
list[:1:-1] means the list *going backwards* up to (but not including) index 1. So, for the list in your example, list[:1:-1] would be [5,4,3,2], since list[1] is 1 and so it is not included in the list slice.
So then list[:1:-1][1] is [5,4,3,2][1] is 4.
0
thanks 👍