Python Programming - Variables - Discussion

Discussion Forum : Variables - General Questions (Q.No. 14)
14.
Which of the following is a valid way to access the last item in a list called my_list?
my_list.last
my_list[-1]
my_list[0]
my_list[len(my_list)]
Answer: Option
Explanation:
In Python, negative indices can be used to access elements from the end of a list. An index of -1 refers to the last item in the list, -2 refers to the second-to-last item, and so on. So my_list[-1] would access the last item in the list.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.