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
?
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:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers