What is the output of the following Python code? print()
Correct answer B. [1, 9]
Explanation
range(5) yields 0 to 4. The condition x % 2 is truthy only for odd numbers, because the remainder 1 is truthy and 0 is falsy. So only 1 and 3 pass the filter, and their squares give [1, 9]. Taking the even numbers instead gives [0, 4, 16], the common misreading.
Answer checked How we write and check questions
Discussion