Informatics Practices

What will be the output of the following operation?

L1 = [1,2] 
L2 = [3, 4] 
(L1 + L2)*2
  1. [2, 4, 6, 8]
  2. [1, 2, 3, 4, 1, 2, 3, 4]
  3. [1, 3, 4, 4]
  4. [3, 4, 1, 2]

Python List Manipulation

3 Likes

Answer

[1,2,3,4,1,2,3,4]

Reason — The code initializes two lists, L1 with elements [1, 2] and L2 with elements [3, 4]. It then concatenates these two lists using the + operator, resulting in [1, 2, 3, 4]. Next, it multiplies this concatenated list by 2 using the * operator, which repeats the elements of the list. Therefore, the final output of (L1 + L2) * 2 is [1, 2, 3, 4, 1, 2, 3, 4].

Answered By

3 Likes


Related Questions