In this example, you will learn to get the last element of this list.
To understand this example, you should have the knowledge of the following Python programming topics:
Using negative indexing
my_list = ['a', 'b', 'c', 'd', 'e'] # print the last element print(my_list[-1])
Output
e
When you use negative indexing, the counting starts from 1 not 0 as shown in the figure below.

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.
Related posts:
Python callable()
Python Program to Add Two Matrices
Python any()
Python Program to Print Hello world!
Python Program to Sort Words in Alphabetic Order
Partition a List in Java
Python String replace()
Python all()
Python Set intersection()
Python frozenset()
Python getattr()
Python Program to Sort a Dictionary by Value
Python List sort()
Python Program to Find ASCII Value of Character
Python String index()
Python Program to Split a List Into Evenly Sized Chunks
Python Iterators
Python min()
Python Statement, Indentation and Comments
Python Errors and Built-in Exceptions
Python String expandtabs()
Python repr()
Python Program to Find Armstrong Number in an Interval
Python Program to Capitalize the First Character of a String
Python hasattr()
Python String isidentifier()
Python max()
Java List UnsupportedOperationException
Python tuple()
Python Program to Get Line Count of a File
Python Anonymous / Lambda Function
Python map()