Python Examples

Python Program to Get the Last Element of the List

In this example, you will learn to get the last element of this list.

Using negative indexing

my_list = ['a', 'b', 'c', 'd', 'e']

# print the last element



When you use negative indexing, the counting starts from 1 not 0 as shown in the figure below.

python list index
List indexing in Python

If you want the first 1st element, you can use my_list[-5].

If you want to learn more, please go to Python list Negative Indexing.


Leave a Reply

Your email address will not be published. Required fields are marked *