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 List copy()
Python open()
Python Set copy()
Python String zfill()
Python String encode()
Building Chatbots with Python Using Natural Language Processing and Machine Learning - Sumit Raj
Python Deeper Insights into Machine Learning - Sebastian Raschka & David Julian & John Hearty
Python Program to Check Leap Year
Python Objects and Classes
Python Machine Learning Second Edition - Sebastian Raschka & Vahid Mirjalili
Python Get Current time
Python Program to Concatenate Two Lists
Python Set symmetric_difference()
Python Program to Shuffle Deck of Cards
Python Program to Print Output Without a Newline
Python bytes()
Python Program to Count the Number of Digits Present In a Number
Converting between an Array and a List in Java
Natural Language Processing with Python - Steven Bird & Ewan Klein & Edward Loper
Python Program to Transpose a Matrix
Python String center()
Python String lower()
Python Dictionary values()
Python Program to Display Powers of 2 Using Anonymous Function
Python round()
Python Dictionary keys()
Python Program to Illustrate Different Set Operations
Python Program to Print the Fibonacci sequence
Python len()
Python Function Arguments
Python Program to Create a Long Multiline String
Python Program to Remove Punctuations From a String