What is the syntax to use negative indexes when using lists?

<array name>[-<index counting from the right, starting at 1>]
#example
flowers=['roses','tulips','daisies','magnolias']
print(flowers[-1])
print(flowers[-2])
print(flowers[-3])
print(flowers[-4])

#output
magnolias
daisies
tulips
roses

 

 

Advertisements