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 Set remove()
Python Program to Get the Full Path of the Current Working Directory
Python Program to Capitalize the First Character of a String
Python Program to Find All File with .txt Extension Present Inside a Directory
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Python String center()
Python String isprintable()
Python sorted()
Python Program to Shuffle Deck of Cards
Python Program to Get a Substring of a String
Python Program to Count the Number of Occurrence of a Character in String
Python Program to Randomly Select an Element From the List
Python bin()
Python Program to Check if a Number is Odd or Even
Python Numbers, Type Conversion and Mathematics
Python List pop()
Python Program to Add Two Matrices
Python staticmethod()
Building Machine Learning Systems with Python - Willi Richert & Luis Pedro Coelho
Python Dictionary update()
Python Program to Find LCM
Python sum()
Python strptime()
Python String encode()
Python Program to Print all Prime Numbers in an Interval
Python Program to Get the File Name From the File Path
Python Function Arguments
Python Inheritance
Python Machine Learning Third Edition - Sebastian Raschka & Vahid Mirjalili
Python String partition()
Python Program to Get Line Count of a File
Python delattr()