Advertisements
Advertisements
Question
If L is a list with 6 elements, then which of the following statements will raise an exception?
Options
L.pop (1)
L.pop (6)
L.insert(1,6)
L.insert(6,1)
MCQ
Advertisements
Solution
L.pop (6)
Explanation:
- Index Range: A list with 6 elements has indices from 0 to 5.
- L.pop(6): This tries to remove an element at index 6, which does not exist. This results in an IndexError.
- L.insert: Unlike
pop, theinsertmethod never raises an error; if the index is too high, it simply adds the item to the end of the list.
shaalaa.com
Is there an error in this question or solution?
