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
list1 = [1, 2, 3, 4, 5]
print(list1[len(list1)-1])
print(list1[-1])
print(list1.pop())
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)
xxxxxxxxxx
data = ["infy", "tcs", "affle", "dixon", "astral"]
last_element = data[-1]
print(last_element)