Python-Quizzes | Python List Quiz | Question 2

Question 2: Find the output of the following program:

filter_none

edit
close

play_arrow

link
brightness_4
code

nameList = ['Harsh', 'Pratik', 'Bob', 'Dhruv'
  
print nameList[1][-1

chevron_right


(A) r
(B) b
(C) D
(D) k


Answer: (D)

Explanation: The index position -1 represents either the last element in a list or the last character in a String. In the above given list of names “nameList”, the index 1 represents the second element i.e, the second string “Pratik” and the index -1 represents the last character in the string “Pratik”. So, the output is “k”.

Quiz of this Question

My Personal Notes arrow_drop_up
Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.