250 views
3 3 votes

Consider the following Python declarations of two lists:

\begin{aligned}
& \mathrm{L} 1=[1,2,3] \\\\
& \mathrm{L} 2=[4,5,6]
\end{aligned}


Which of the following statement(s) results in $\mathrm{L1}=[1,2,3,4,5,6]$ ?

  1. $\mathrm{L1}=\mathrm{L1}+\mathrm{L2}$
     
  2. $\mathrm{L1}.$extend$(\mathrm{L2})$
     
  3. $\mathrm{L1}.$append$(\mathrm{L2})$
     
  4. $\mathrm{L1} = \mathrm{L2}.$extend$(\mathrm{L1})$

1 Answer

0 0 votes

(A) $\mathrm{L1}=\mathrm{L1}+\mathrm{L2}$ This performs concatenation. It creates a new list by joining L1 and L 2 and then assigns this new list back to the variable L 1 . The result is $[1,2,3,4,5,6]$.

(B) $\mathrm{L1}.$extend$(\mathrm{L2})$: The .extend() method is a mutator. It takes an iterable (L2) and adds all its elements to the end of the original list (L1) in-place. The result is L1 = $[1,2,3,4,5,6]$.

(C) $\mathrm{L1}.$append$(\mathrm{L2})$: The .append() method adds its argument as a single element to the end of the list. The result would be $\mathrm{L1}=[1,2,3,[4,5,6]]$.

(D) $\mathrm{L1} = \mathrm{L2}.$extend$(\mathrm{L1})$: The .extend() method, being an in-place mutator, returns None. This statement would assign None to L1, making L1 $=$ None.

Answer:
Position:
Show:

Related questions

2 2 votes
1 1 answer
249
249 views
GO Classes asked Dec 16, 2025
249 views
A singly linked list $\text{L}$ is constructed by linking nodes. Each node contains a data field and a $\text{NEXT}$ pointer.Consider the following function, $\text{proce...
0 0 votes
1 1 answer
225
225 views
GO Classes asked Dec 16, 2025
225 views
A queue $\mathrm{Q}$ can be implemented using two stacks, $\mathrm{S}_{\text {IN }}$ (for $\operatorname{ENQUEUE}$ and $\mathrm{S}_{\text {OUT }}$ (for $\operatorname{DQU...
1 1 vote
1 1 answer
264
264 views
GO Classes asked Dec 16, 2025
264 views
Consider a function modify $(\mathrm{Q})$ that uses a single temporary stack $\mathrm{S}$ to process a queue $\mathrm{Q}$. Initially, $\mathrm{Q}$ contains the elements: ...
0 0 votes
1 1 answer
253
253 views
GO Classes asked Dec 16, 2025
253 views
Consider the following Python code snippet:def mystery(a, b): if a <= 0: return b if a % 2 == 0: return mystery(a // 2, b + b) else: r...