1# To get the last element in a list you use -1 as position
2bikes = ['trek', 'redline', 'giant']
3bikes[-1]
4# Output:
5# 'giant'
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]
1>>> l = list(range(1,5))
2>>> l
3[1, 2, 3, 4]
4>>> l.pop()
54
6>>> l
7[1, 2, 3]
8
1# Basic syntax:
2your_list[-1]
3
4# Example usage:
5your_list = [1, 'amazing', 'list']
6your_list[-1]
7--> 'list'