l = [1, 2, 3] l[-1]
mylist = [0, 1, 2] mylist[-1] = 3 # sets last element print(myList[-1]) # prints Last element
number_list = [1, 2, 3] print(number_list[-1]) #Gives 3 number_list[-1] = 5 # Set the last element print(number_list[-1]) #Gives 5 number_list[-2] = 3 # Set the second to last element number_list [1, 3, 5]
print(list[-1])
some_list = [1, 2, 3] some_list[-1] print(some_list) #Output = 3
# Basic syntax: your_list[-1] # Example usage: your_list = [1, 'amazing', 'list'] your_list[-1] --> 'list'
your_list = ["apple", "orange", "grapes"] last_value = your_list[-1]
x = [1, 2, 3, 4] #same array, but the last item. notLast = x[0:-1]