Find the Last Element of a List in Python Using Slicing
(Last Updated On: 24/02/2023)
Python Program to Find the Last Element of a List Using Slicing
# Get the Last Element of the List in python Using slicing
# input list
inputList = [5, 1, 6, 8, 3]
# printing input list
print("Input list:", inputList)
# getting the last element of the list using slicing
lastElement = inputList[-1:][0]
# printing the last element of the list
print("Last element of the input list = ", lastElement)
Output:
Input list: [5, 1, 6, 8, 3]
Last element of the input list = 3