2nd to last index python 1

2nd to last index python

# python code to get 2nd to last item in a list
my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
print(my_list[-2])

Here is what the above code is Doing:
1. We create a list called my_list.
2. We print the second to last item in the list.
3. We use the index -2 to get the second to last item in the list.

Similar Posts