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 Add Two Matrices
Python Dictionary copy()
Deep Learning with Python - Francois Cholletf
Python String format()
Python String encode()
Python enumerate()
Python String ljust()
Python Dictionary fromkeys()
Python print()
Python Data Structures and Algorithms - Benjamin Baka
Python Program to Extract Extension From the File Name
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Python Global Keyword
Python while Loop
Python Program to Get File Creation and Modification Date
Python Errors and Built-in Exceptions
Python Program to Make a Simple Calculator
Python getattr()
Python isinstance()
Python String format_map()
Python frozenset()
Python File I/O Operation
Python Set union()
Python property()
Python Program to Convert Kilometers to Miles
Converting Between a List and a Set in Java
Deep Learning with Applications Using Python - Navin Kumar Manaswi
Python Program to Compute all the Permutation of the String
Python del Statement
Ways to Iterate Over a List in Java
Python Set update()
Python Program to Find the Factors of a Number