Question:

Given the lists: \[ A = [1,2,3], \quad B = [4,5,6] \] Which of the following statements will result in \[ A = [1,2,3,4,5,6]? \]

Show Hint

Use \texttt{extend()} to concatenate lists in Python, as it adds each element individually instead of nesting lists.
Updated On: Feb 15, 2025
  • A.append(B)
  • A.update(B)
  • A.insert(B)
  • A.extend(B)
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is D

Solution and Explanation

- The method \texttt{A.append(B)} treats the entire list \( B \) as a single element, leading to \([1,2,3,[4,5,6]]\), which is incorrect. - The method \texttt{A.update(B)} is not applicable to Python lists, as it is used for sets and dictionaries. - The method \texttt{A.insert(B)} is incorrect because \texttt{insert()} requires both an index and a value, making it unsuitable for concatenating lists. - The correct approach is \texttt{A.extend(B)}, which adds each element of \( B \) individually to \( A \), resulting in \([1,2,3,4,5,6]\). Conclusion: The correct method is \texttt{A.extend(B)}, as it appends the individual elements of \( B \) to \( A \) rather than nesting the list.
Was this answer helpful?
0
0