Anomaly
0
Q:

how to find the last item of a list

mylist = [0, 1, 2]
mylist[-1] = 3 # sets last element
print(myList[-1]) # prints Last element
12
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]
8
print(list[-1])
3
list1 = ['a','b','c']
print(list1[-1])

3
some_list = [1, 2, 3]
some_list[-1]
print(some_list)
#Output = 3
1
L=[1,2,3,4,5]
lastElement=L[L.size()]
0

New to Communities?

Join the community