How to Get Second Last Element of List in Python?

Published On: 25/03/2025 | Category: Python
Python Get Second Last Element of List

Hi Guys,

In this beginner-friendly Python tutorial, you will learn how to get the second last element from a list in Python. If you're working with lists and need to access items from the end, this guide will be especially useful.

We'll walk through simple examples to help you understand how to find the second last item in a list using negative indexing and the pop() method. Whether you're just starting with Python or want to brush up on list handling, this tutorial has you covered.

There are a couple of ways to get the second last element from a Python list. We'll cover these two common approaches:

  • Using Negative Indexing: list[-2]
  • Using pop() to remove elements until second last

Let’s go through an example together.

Example 1

main.py
myList = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']

# Get Second Last Element
second_last = myList[-2]

print(second_last)
Output
Fri

This works because Python allows negative indexing where -1 refers to the last element, and -2 refers to the second last.

FAQs - Python List Indexing

Q1: What is the syntax to get the second last element in a Python list?
A: You can use list[-2] to get the second last element.

Q2: What if my list has less than 2 elements?
A: It will raise an IndexError. Always check list length before accessing list[-2].

Q3: Can I use pop() to get the second last element?
A: Yes, but you’d need to remove the last element first using pop() and then get the last from the updated list.

Q4: Is list[-2] more efficient than other methods?
A: Yes, because it directly accesses the memory index without modifying the list.

Q5: Can I use this for tuples and strings?
A: Yes, both support indexing in the same way as lists.

I hope this helps you understand how to access elements from the end of a list in Python.

Happy Pythonic Coding!