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:
Convert a Map to an Array, List or Set in Java
Python dir()
Python Set add()
Python Input, Output and Import
Python break and continue
Python Set isdisjoint()
Removing all duplicates from a List in Java
Python Program to Remove Duplicate Element From a List
Python Program to Check If Two Strings are Anagram
Python Set intersection_update()
Python zip()
Python Program to Compute all the Permutation of the String
Python time Module
Python String ljust()
Python Set clear()
Python Program to Print Output Without a Newline
Python Program to Convert Decimal to Binary, Octal and Hexadecimal
Python Errors and Built-in Exceptions
Python Global Keyword
Python Variables, Constants and Literals
Python Program to Compute the Power of a Number
Python Program to Extract Extension From the File Name
Python List reverse()
Python Package
Python Program to Iterate Over Dictionaries Using for Loop
Python while Loop
Python Program to Sort a Dictionary by Value
Python divmod()
Python Shallow Copy and Deep Copy
Python Set pop()
Python @property decorator
Python Objects and Classes