The GATE Grind

GATE 2025 DA – Question 23

Programming, Data Structures and Algorithms · Programming in Python · 1 mark · Multiple choice

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. A.extend(B)
  2. A.append(B)
  3. A.update(B)
  4. A.insert(B)

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (A) A.extend(B)

Explanation

`extend` adds every element of B to the end of A, giving [1, 2, 3, 4, 5, 6]. `append` would add B as a single element, giving [1, 2, 3, [4, 5, 6]]. Lists have no `update` method (that is for dictionaries and sets), and `insert` needs an index as well as a value.