Negative Indexing in Python


Access elements from the end of a list.

Source Code

my_list = [1, 2, 3, 4, 5]
print(my_list[-1])  # Last item
print(my_list[-2])  # Second to last item
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments