What will be the output of the following Python code? [code]l=[1, 0, 2, 0, 'hello', '', []] list(filter(bool, l))[/code]

What will be the output of the following Python code?
Code:
l=[1, 0, 2, 0, 'hello', '', []]
list(filter(bool, l))
A. Error
B. [1, 0, 2, 0, ‘hello’, ”, []]
C. [1, 0, 2, ‘hello’, ”, []]
D. [1, 2, ‘hello’]
 
Answer: d
Explanation: The code shown above returns a new list containing only those elements of the list l which do not amount to zero. Hence the output is: [1, 2, ‘hello’].
 

Tìm kiếm

Back
Top