A question about calling [n] elements from the list

So, I want to directly ask my question.
Suppose we have a list called “list”.

list = [“a”, “b”, “c”, “d”, “e”]

list[0:2] prints → “a” , “b”
list[-1] prints → “e” because “e” is index -1.
list[-2] prints → “d” because “d” is index -2.

so when we want so slice the list:

list[-2:] prints → “d” , “e”
list[:-1] prints → “a”, “b”, “c”, “d”

so what I wonder is, when we say list[0:2] → “a” and “b” because we don’t count the index 2, but when we say list[-2:] it prints “d” , “e”. Shouldn’t it print only “e” since we don’t count the last index, which is index -2 at this moment?

When using slice notation in Python, the starting index is inclusive (included in the slice) while the ending index is exclusive (not included in the slice).

So when we use list[0:2], it includes the elements at index 0 and 1, but not 2.

Similarly, when we use list[:-1], it includes all the elements from the beginning of the list up to the element at index -1, but not the element at index -1.

However, when we use negative indices in a slice like list[-2:], it includes all the elements starting from the element at index -2 up to the end of the list.

So list[-2:] includes the elements at indices -2 and -1, which are “d” and “e”, respectively.

Therefore, list[-2:] prints “d”, “e”, not just “e”.