Python assigns -1 to the index of the last element of a list and you can get the last element using this index value as shown in the below example –
1 2 3 4 5 |
l = [1,2,3,4,5,6] print(l[-1]) ## Returns 6 ## If the list is empty use l[-1:] to avoid exception |