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 ord()
Using a List of Values in a JdbcTemplate IN Clause
Python divmod()
Python frozenset()
Python @property decorator
Python Machine Learning Eqution Reference - Sebastian Raschka
Python Dictionary update()
Python issubclass()
Python print()
Python exec()
Python min()
Python List copy()
Python Set symmetric_difference()
Python super()
Python Deep Learning - Valentino Zocca & Gianmario Spacagna & Daniel Slater & Peter Roelants
Python bin()
Python List insert()
Python Dictionary pop()
Remove All Occurrences of a Specific Value from a List
Python Program to Display the multiplication Table
Python Program to Return Multiple Values From a Function
Python isinstance()
Python List sort()
Python range()
Python String isidentifier()
Python int()
APIs in Node.js vs Python - A Comparison
Python String maketrans()
Java List UnsupportedOperationException
Python Directory and Files Management
Python Deeper Insights into Machine Learning - Sebastian Raschka & David Julian & John Hearty
Python Machine Learning Third Edition - Sebastian Raschka & Vahid Mirjalili