+ 1
Can anyone tell the reason of the output
t=[1,2,4,3] t[1:-1]
2 ответов
+ 1
Here is the explanation :
t = [1,2,4,3]
print(t[1:-1]) # [2,4]
The output is [2,4]. Because '-1' means till the last element. And '1' means from the first element. So '1:-1' means between first element to last element. The first element is 1 and the last element is 3. We have 2,4 between them. Therefore the answer is [2,4].
Again consider this :
print(t[:-1]) # [1,2,4]
print(t[1:]) # [2,4,3]
+ 1
Thanks for answering 🙏