if item is last in list python code example
Example 1: check if is the last element in list python
if x == my_list[-1]:
# do what you want
Example 2: python last element of list
>>> list[-1:] # returns indexed value
[3]
>>> list[-1] # returns value
3