Проверьте, является ли последний элемент в списке Python
if x == my_list[-1]:
# do what you want
Marton
if x == my_list[-1]:
# do what you want
list1 = ['a','b','c']
print(list1[-1])
your_list = ["apple", "orange", "grapes"]
last_value = your_list[-1]
>>> 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]
some_list = [1,2,3]
some_list[-1] is the shortest and most Pythonic.
#output = 3
data = ["infy", "tcs", "affle", "dixon", "astral"]
last_element = data[-1]
print(last_element)