Skip to content
Question 39 of 97

Q.If L is a list with 6 elements, then which of the following statements will raise an exception ? (A) L.pop(1) (B) L.pop(6) (C) L.insert(1,6) (D) L.insert(6,1)

Sikkim CbseCBSE Class XII Board 2026MCQ· 1mImportance★★★★★
40% · 39/97 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

Python lists are 0-indexed. For a list of length 6, valid indices for pop() are 0 to 5, so L.pop(6) raises an IndexError. insert() is more forgiving — an index at or beyond the end just appends. The answer is (B) L.pop(6).

Python lists are 0-indexed, and the key is how different list methods treat an index at the boundary.

For a list L with 6 elements, the valid indices for accessing or removing an existing element are 0, 1, 2, 3, 4, 5. Any attempt to remove an element at an index outside this range raises an IndexError.

The insert() method behaves differently: it says where to place a new element. If the index equals the list length, the element is appended; if the index is even larger, it is still appended. So insert() is more forgiving than pop().

Take a sample list L = [10, 20, 30, 40, 50, 60] where len(L) is 6.

  1. (A) L.pop(1) — index 1 exists, so this removes 20. No exception.

  2. (B) L.pop(6) — pop() needs 0 <= index < len(L). Here len(L) is 6, so the valid indices are 0 to 5. Index 6 is out of range, so this raises an IndexError.

    Watch out

    A common mistake is confusing the length of the list with the highest valid index. For a list of length N, the highest valid index is N minus 1, not N. …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.