ItSolutionStuff.com

Python Get Second Last Element of List Example

By Hardik Savani • October 30, 2023
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: Python
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Get First Element of List in Python?

Read Now →

How to Remove Last Element from List in Python?

Read Now →

How to Remove First Element from List in Python?

Read Now →

Python List Remove Element by Value Example

Read Now →

Python List Remove Element by Index Example

Read Now →

How to Get All Files from Directory in Python?

Read Now →

Python Post Request with Basic Authentication Example

Read Now →

Python Post Request with Bearer Token Example

Read Now →

Python Get First Date of Last Month Example

Read Now →

Python Get First Date of Next Month Example

Read Now →

Python Create Zip Archive from Directory Example

Read Now →

How to Compare Two Dates in Python?

Read Now →

How to Check if Today is Monday or not in Python?

Read Now →