1>>> myList = list(range(1,5))
2>>> myList
3[1, 2, 3, 4]
4>>> myList = myList[:-1]
5>>> myList
6[1, 2, 3]
1number_list = [1, 2, 3]
2print(number_list[-1]) #Gives 3
3
4number_list[-1] = 5 # Set the last element
5print(number_list[-1]) #Gives 5
6
7number_list[-2] = 3 # Set the second to last element
8number_list
9[1, 3, 5]
1my_list = ['red', 'blue', 'green']
2# Get the last item with brute force using len
3last_item = my_list[len(my_list) - 1]
4# Remove the last item from the list using pop
5last_item = my_list.pop()
6# Get the last item using negative indices *preferred & quickest method*
7last_item = my_list[-1]
8# Get the last item using iterable unpacking
9*_, last_item = my_list