04-Nov-2022
.
Admin
Hi Dev,
In this post, we will learn Get Second Last Element of List in Python Example. step by step explain Python Array Get Second Last Element. I would like to share with you How to Get Second Last Element of List in Python. I would like to show you Python Get Second Item in List.
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.
so let's see following examples with output:
Example:
main.py
myList = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
# Get Last Element
lastElem = myList[-2]
print(lastElem)
Output:
Fri
#Python