GATE DA 2025 · Programming in Python

MCQ · 1 mark · Problem PROG-PYTH-0012

Consider the following Python declarations of two lists:\(A = [1, 2, 3], \quad B = [4, 5, 6]\)Which one of the following statements results in \(A = [1, 2, 3, 4, 5, 6]\)?
  1. A
    \(A.\text{extend}(B)\)
  2. B
    \(A.\text{append}(B)\)
  3. C
    \(A.\text{update}(B)\)
  4. D
    \(A.\text{insert}(B)\)

Solve it on GATE DA practice →More Python Programming problems

Show the worked solution\(A.\text{extend}(B)\) adds all elements of \(B\) individually onto the end of \(A\), giving exactly \([1,2,3,4,5,6]\).\(A.\text{append}(B)\) would instead add the entire list \(B\) as a single nested element, giving \([1,2,3,[4,5,6]]\) (wrong). \(\text{update}\) and \(\text{insert}(B)\) either don't exist as plain list methods in this form or don't produce a flat concatenated list.Answer: A.extend(B)Click Here for Detail SolutionGateOverflow discussion: https://gateoverflow.in/461009/gate-da-2025-question-13

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com