In Python, how do you get the last element of a list?
Here is the solution for your query.
a=["first","middle","last"] # A sample list
print(a[0]) #prints the first item in the list because the index of the list always starts from 0.
print(a[-1]) #prints the last item in the list.
print(a[-2]) #prints the last second item in the list.
Output:
>>> first
>>> last
>>> middle