How to get the last element of array in python

How to get the last element of array in python

in this tutorial we'll learn how to get the last item of array

syntax

1
2
#syntax
array[-1]

example

1
2
3
4
5
6
7
8
#array
array = ['Dog', 'Cat', 'Zebra', 'Tiger']

#get the last element
last_element = array[-1]

#print
print(last_element)

output

Tiger