How would you access the last element of a list stored in a variable named my_list?

  • my_list[-1]
  • my_list[0]
  • my_list[1]
  • my_list[len(my_list)]

In Python, my_list[-1] is used to access the last element of a list. my_list[0] would access the first element. my_list[1] would access the second element. my_list[len(my_list)] would cause an IndexError as the index would be out of range.

Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *