List operation with [-1].Explain

1 answer

  • answered 2019-04-15 06:08 prashant

    list[-1] returns the last element of the list e.g

    array = [1,2,3]
    print array[-1]  # outputs 3