GATE 2025 DA – Question 23
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]?
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.