Python-Quizzes | Python List Quiz | Question 14

Question 14: Find the output of the following program:

filter_none

edit
close

play_arrow

link
brightness_4
code

list = ['a', 'b', 'c', 'd', 'e'
print(list[10:] )

chevron_right


(A) [‘a’, ‘b’, ‘c’, ‘d’, ‘e’]
(B) [ ‘c’, ‘d’, ‘e’]
(C) [ ]
(D) [‘a’, ‘b’]


Answer: (C)

Explanation: As one would expect, attempting to access a member of a list using an index that exceeds the number of members (e.g., attempting to access list[10] in the list above) results in an IndexError. However, attempting to access a slice of a list at a starting index that exceeds the number of members in the list will not result in an IndexError and will simply return an empty list.

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.