Test Index

CBSE Class 12 Computer Science 2026 Paper Set 4 Get it on Google PlayDownload on the App Store

© examsnet.com
Question : 8 of 37
Marks: +1, -0
If L is a list with 6 elements, then which of the following statements will raise an exception ?
Solution:  
Concept:
A list of 6 elements has valid indices 0 to 5 (and -1 to -6).
pop(i) removes and returns the element at index i; an index outside the list raises IndexError.
insert(i, x) never raises an error for a large index: if i is beyond the end, x is simply appended.
Explanation:
(A) L.pop(1) removes the 2nd element: no error.
(B) L.pop(6): index 6 does not exist → IndexError: pop index out of range.
(C) L.insert(1,6) inserts 6 at index 1: no error.
(D) L.insert(6,1) inserts 1 at index 6, i.e. at the end: no error.
Answer:
Option B (L.pop(6))
© examsnet.com
Advertisements
Go to Question: