Think of the indexes as dividers right after an element. e.g.
Given list ['a', 'b', 'c']
Positive indexes (indexes in |n|): ['a'|0| 'b'|1| 'c'|2|]
Negative indexes (indexes in |n|), I'm gonna show the list in reverse so it's a bit more clear: ['c'|-1| 'b'|-2| 'a'|-3|]
or in the original direction (but think of it starting from the end) [|-3|'a' |-2|'b' |-1|'c']
So in your example: a=['c','b']
your negative indexes are [|-2|'c' |-1|'b']
but when you're doing a range, Python doesn't complain when you pass an out of scope starting index of -3
. In fact you can pass in any arbitrary indexes when you do a range and Python won't complain. Try for example [-10:-5]
, but because in your case your range does contain 'c'
, that's all you get.