GATE DA 2025 | Question 23

MCQ · 1 mark · −0.33

Consider the following Python declarations of two lists.

A=[1,2,3]
B=[4,5,6]

Which one of the following statements results in A= \([1, 2, 3, 4, 5, 6]\)?

  1. Option A: A.extend(B) (correct)
  2. Option B: A.append(B)
  3. Option C: A.update(B)
  4. Option D: A.insert(B)

Answer

(A)

Explanation

A.extend(B) adds each element of B to the end of A in place, so A becomes [1, 2, 3, 4, 5, 6].

  • A.append(B) adds the whole list as a single element, giving [1, 2, 3, [4, 5, 6]].
  • Lists have no update method (dictionaries and sets do), so option C raises AttributeError.
  • insert needs two arguments, an index and a value, so A.insert(B) raises TypeError.

Answer: A