GATE DA 2025 | 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]\)?
Explanation
Answer: (A)
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
updatemethod (dictionaries and sets do), so option C raisesAttributeError. insertneeds two arguments, an index and a value, soA.insert(B)raisesTypeError.
Answer: A