What will be the output of the following Python code? [code]l=[1,2,3,4,5] [x&1 for x in l][/code]

What will be the output of the following Python code?
Code:
l=[1,2,3,4,5]
[x&1 for x in l]
A. [1, 1, 1, 1, 1]
B. [1, 0, 1, 0, 1]
C. [1, 0, 0, 0, 0]
D. [0, 1, 0, 1, 0]
 
Answer: b
Explanation: In the code shown above, each of the numbers of the list, that is, 1, 2, 3, 4 and 5 are AND-ed with 1 and the result is printed in the form of a list. Hence the output is [1, 0, 1, 0, 1].
 

Tìm kiếm

Back
Top