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 to Merge Two Dictionaries
Python strptime()
Python if...else Statement
Python Set issuperset()
Python Program to Sort Words in Alphabetic Order
Python del Statement
Converting Iterator to List
Python complex()
Python Program to Convert Kilometers to Miles
Python time Module
Python Set copy()
Python dir()
Python List Comprehension
How to Convert List to Map in Java
Python Directory and Files Management
Python Program to Find the Sum of Natural Numbers
Python String split()
Python String maketrans()
Python Program to Count the Number of Each Vowel
Python Dictionary
Python all()
Python Program to Get File Creation and Modification Date
Python Set union()
Python Program to Make a Flattened List from Nested List
Python String expandtabs()
Python Dictionary clear()
Python Program to Get the Full Path of the Current Working Directory
Python Tuple count()
Python int()
Python String partition()
Python String count()
Python exec()