+ 1
How is this working
Lst=[1,2,3,4,5,6,7,8] print(Lst[-100:3]) Output: 1,2,3 Can anyone please explain what is Lst[-100:3]
2 Answers
+ 2
[-100:3] I think is what you meant not [-100,3] because that will give you an error.
Negative indices count from the end of the list towards the front. Once the front is reached it goes no further. So the same would be accomplished using [-8:3]
Any index -8 or smaller in a list of this size would be equivalent to an index of 0.
-7 would be equivalent to an index of 1
-1 would be the last element in the list
+ 1
I think (apart from auro-capitalized text) you have syntax error there. You probably meant
print(Lst[-100 : 3])
Instead of
print(Lst[-100, 3])
Notice the former is list slice.
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2453/