list = [4,3,2,5,4]
last=list[len(list)-1]
some_list[-1]
array = ["a", "b", "c", "d"]
num_elements = 3
print(array[-num_elements:])
arr = ["cat", "dog", "rabbit"]
last_element = arr[-1]
# To get the last 2 elements in a list you use -2: as position
bikes = ['trek', 'redline', 'giant']
bikes = bikes[-2:]
# Output:
# ['redline', 'giant']
>>> some_list = [1, 2, 3]
>>> some_list[-1] = 5 # Set the last element
>>> some_list[-2] = 3 # Set the second to last element
>>> some_list
[1, 3, 5]