Skip to content
Sign in
Computer

What is the output of the following python code? a= [1, 2, 3, 4] b= [num * 2 for num in a if num % = = θ] print(b)

Tap an option to check the answer. You can also press A–D.

Show answer

Correct answer: C) [4, 8]

The list comprehension iterates through a, checks if num is even (num % 2 == 0), and if true, multiplies num by 2.For the list a = [1, 2, 3, 4], the even numbers are 2 and 4. Multiplying them by 2 gives 4 and 8.Output: [4, 8]
Explanation
The list comprehension iterates through a, checks if num is even (num % 2 == 0), and if true, multiplies num by 2.For the list a = [1, 2, 3, 4], the even numbers are 2 and 4. Multiplying them by 2 gives 4 and 8.Output: [4, 8]