Python Get Last Element of List Example
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:
myList = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'] # Get Last Element lastElem = myList[-1] print(lastElem)Output
myList = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'] # Get Last Element lastElem = myList.pop() print(lastElem)Output
It will help you....
Happy Pythonic Coding!