Python Program to Get the Last Element of the 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.

Negative Indexing
List indexing in Python

If you want the first 1st element, you can use my_list[-5].


Also Read:

Did you find this article helpful?

Our premium learning platform, created with over a decade of experience and thousands of feedbacks.

Learn and improve your coding skills like never before.

Try Programiz PRO
  • Interactive Courses
  • Certificates
  • AI Help
  • 2000+ Challenges