What will the following code display?
numbers = [1, 2, 3, 4, 5]
print(numbers[-2])
numbers = [1, 2, 3, 4, 5]
print(numbers[-2])
output:
4
the index of 1 is 0,the index of 2 is 1 and so on....
2.But in the question, negative slicing had implemented,,that means, indexing is considered from the right to left
-1 means the last element, -2 means the second last element, and so on.
so here,the given index is -2,therefore the negative index of 4 in the list wll be -2