Python Get Second Last Element of List Example

By Hardik Savani October 30, 2023 Category : Python

Now, let's see the article of python get second last element of list. I explained simply step by step how to find second last element in list python. you will learn python get second item in list. you will learn how to get second last element of list in python. you will do the following things for python array get second last element.

In this example, I will create a simple list with the day with the name. Then I will get second last element with name using -2 key of array. so let's see the below example.

You can use these examples with python3 (Python 3) version.

let's see below a simple example with output:

Example:

main.py

myList = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
  
# Get Last Element
lastElem = myList[-2]
  
print(lastElem)

Output:

Fri

I hope it can help you...

Tags :
Shares