Question 81 markMCQSection A

If L is a list with 6 elements, then which of the following statements will raise an exception ?

Review of Python Basics (Class XI Recap)
Lists — pop() and insert() Methods

Options

(A)L.pop(1)
(B)L.pop(6)
(C)L.insert(1,6)
(D)L.insert(6,1)

Official answer

Option B — L.pop(6) raises an exception, because a list L with 6 elements has valid indices only from 0 to 5; index 6 is out of range for pop().

Answer keywords:list pop()list insert()IndexErrorlist methodsindex out of rangePython lists

Marking scheme

  1. 1.1 mark: for correctly selecting option B.

Hint

pop() needs a valid EXISTING index and raises IndexError if out of range; insert() never raises IndexError — it just clamps to a valid position.

Quick oral answer

L.pop(6) raises an exception because a 6-element list only has valid indices 0 to 5; insert(), unlike pop(), never raises IndexError since it clamps out-of-range indices to the end of the list.

Common mistakes

  1. 1.Assuming insert() behaves like pop() and raises an error for out-of-range indices.
  2. 2.Forgetting that valid indices for a 6-element list only go up to 5, not 6.

Analysis and explanation

This question tests the boundary behaviour of list methods pop() and insert(), which behave differently when given an out-of-range index.


Concept

  • For a list L with 6 elements, valid (0-based) indices are 0, 1, 2, 3, 4, 5.
  • pop(index) REMOVES and returns the element at that index — it strictly requires a valid existing index, else it raises IndexError: pop index out of range.
  • insert(index, value) INSERTS a new value at that position — it never raises an error for out-of-range indices; if the index exceeds the list's length, Python simply inserts the value at the end.

Option-by-option check

  • A: L.pop(1) — index 1 is valid (0 to 5); works fine.
  • B: L.pop(6) — index 6 does NOT exist (max valid index is 5); raises IndexError. This is the correct answer.
  • C: L.insert(1,6) — inserts value 6 at index 1; valid, no error.
  • D: L.insert(6,1) — index 6 is beyond the last valid index, but insert() clamps out-of-range indices and simply appends the value at the end; no error.

Exam trap

  • Students often assume insert() will also raise an error like pop() for an out-of-range index — but insert() is designed to be error-tolerant and always succeeds by clamping to the nearest valid position.

Interesting facts

insert() with an index far beyond the list length (e.g., L.insert(100, 'x')) still works without error — it just appends the value at the very end.

pop() with no argument at all removes and returns the LAST element of the list, equivalent to pop(-1).

Question details

Q8 of 48 questions

Board
CBSE
Class
Class 12
Subject
Computer Science
Year
2026
Section
Section A
Marks
1
Type
MCQ
Chapter
Review of Python Basics (Class XI Recap)
Topic
Lists — pop() and insert() Methods
Bloom's level
apply
Syllabus topic
Unit 1: Computational Thinking and Programming – 2 — Lists: pop() and insert() Methods, IndexError
Author
CBSE
Reviewed by
Padhantu Academic Team

Spotted a mistake or something unclear?

Tell us and we will fix it.

Frequently asked questions

Does insert() ever raise an IndexError in Python?

No. insert() never raises an IndexError for out-of-range indices — if the given index exceeds the list length, the value is simply inserted (appended) at the end of the list.

What error does pop() raise for an invalid index?

It raises `IndexError: pop index out of range` when the given index does not correspond to an existing element in the list.