Python Get Second Last Element of List Example
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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Get First Element of List in Python?
- How to Remove Last Element from List in Python?
- How to Remove First Element from List in Python?
- Python List Remove Element by Value Example
- Python List Remove Element by Index Example
- How to Get All Files from Directory in Python?
- Python Post Request with Basic Authentication Example
- Python Post Request with Bearer Token Example
- Python Get First Date of Last Month Example
- Python Get First Date of Next Month Example
- Python Create Zip Archive from Directory Example
- How to Compare Two Dates in Python?
- How to Check if Today is Monday or not in Python?