xxxxxxxxxx
mylist = [0, 1, 2]
mylist[-1] = 3 # sets last element
print(myList[-1]) # prints Last element
xxxxxxxxxx
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]
xxxxxxxxxx
my_list = ["I", "Love", "Python"]
last_item_in_list = my_list[-1]
# last_item_in_list = "Python"
xxxxxxxxxx
MyList = [1, 2, 3, 4, 5]
print(MyList[len(Mylist)-1])
# Makes you look professional
xxxxxxxxxx
>>> a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
>>> a
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
>>> a[-9:]
[4, 5, 6, 7, 8, 9, 10, 11, 12]
xxxxxxxxxx
numbers = [1, 4, 56, 78, 32, 3, 45]
last_number = numbers[-1]
print("Last element in the list:", last_number)
xxxxxxxxxx
# Assuming the list is already defined
my_list = [1, 2, 3, 4, 5]
# Get the last element using indexing
last_element = my_list[-1]
print(last_element)