Lucia
0
Q:

get every item but the last item of python list

l = [1, 2, 3]
l[-1]
6
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
some_list = [1, 2, 3]
some_list[-1]
print(some_list)
#Output = 3
1
# Basic syntax:
your_list[-1]

# Example usage:
your_list = [1, 'amazing', 'list']
your_list[-1]
--> 'list'
1
your_list = ["apple", "orange", "grapes"]
last_value = your_list[-1]
1
x = [1, 2, 3, 4]

#same array, but the last item.
notLast = x[0:-1]
0

New to Communities?

Join the community