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 Program Read a File Line by Line Into a List
Python break and continue
Python format()
Python String lower()
Python globals()
Python abs()
Python Dictionary
Python Set issubset()
Python for Loop
Python Generators
Python object()
Python Tuple count()
Python String isalnum()
Python min()
Python Machine Learning Eqution Reference - Sebastian Raschka
Python Set symmetric_difference()
Python hex()
Python Anonymous / Lambda Function
Python Machine Learning Second Edition - Sebastian Raschka & Vahid Mirjalili
Python Data Structures and Algorithms - Benjamin Baka
Python list()
Python reversed()
Python String isalpha()
Python Dictionary pop()
Python Variables, Constants and Literals
Python Function Arguments
Python String replace()
Python Program to Check Prime Number
Python Program to Differentiate Between type() and isinstance()
Python del Statement
Python Modules
Python Program to Capitalize the First Character of a String