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 any()
Python bin()
Python Set update()
Python chr()
Python List clear()
Python Program to Copy a File
Python Type Conversion and Type Casting
Python reversed()
Python Machine Learning Third Edition - Sebastian Raschka & Vahid Mirjalili
Python Object Oriented Programming
Python Program to Display Fibonacci Sequence Using Recursion
Python Program to Remove Duplicate Element From a List
Python Program to Create Pyramid Patterns
Python enumerate()
Python Program to Convert Celsius To Fahrenheit
Python min()
Python format()
Python while Loop
Python Program to Find HCF or GCD
Python Machine Learning - Sebastian Raschka
Python Set discard()
Python Set intersection_update()
Python Program to Print Colored Text to the Terminal
Python Namespace and Scope
Python Program to Find the Sum of Natural Numbers
Python filter()
Python String zfill()
Python Program to Slice Lists
How to Convert List to Map in Java
Python help()
Python Program to Find the Factorial of a Number