1# The smart way
2
3list = ["first item", "second item", "third item"]
4print(list[len(list) - 1])
5
6# The proper way
7print(list[-1])
1import operator
2# Python code to access the last element
3# in a list using itemgetter() method
4
5# Declaring and initializing list
6number_list = [2, 1, 7, 4, 5, 3,6]
7
8print ("List of elements are : " + str(number_list))
9
10getLastElement = operator.itemgetter(-1)
11
12
13# using [] operator to print last element
14print("The last element of list using reverse method are : "
15 + str(getLastElement(number_list)))
16