python how to get last element of array code example
Example 1: get last element of array python
some_list[-1]
Example 2: python get last element of list
mylist = [0, 1, 2]
mylist[-1] = 3 # sets last element
print(myList[-1]) # prints Last element
Example 3: get the last element of a list python
print(list[-1])
Example 4: How to find last element in array python
>>> 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]
Example 5: python last element of list
>>> list[-1:] # returns indexed value
[3]
>>> list[-1] # returns value
3