Python Get Last Element of List Example

Published On: 08/11/2022 | Category: Python


Hi Guys,

Are you looking for example of python get last element of list of lists. you'll learn python get last element from list. let’s discuss about how to get last element of list in python. This article goes in detailed on how to get last n elements of a list in python. Alright, let’s dive into the steps.

There are a few ways to get the last element from the list in python. You could use either by key with -1 or using pop function. so let's see the below examples:

So let's see bellow example:

Example 1

main.py
myList = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
  
# Get Last Element
lastElem = myList[-1]
  
print(lastElem)
Output
Sat

Example 2

main.py
myList = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
  
# Get Last Element
lastElem = myList.pop()
  
print(lastElem)
Output
Sat

It will help you....

Happy Pythonic Coding!