Python-Quizzes | Python List Quiz | Question 17

Question 17: Find the output of the following program:

filter_none

edit
close

play_arrow

link
brightness_4
code

data = [x for x in range(5)] 
temp = [x for x in range(7) if x in data and x%2==0
print(temp) 

chevron_right


(A) [0, 2, 4, 6]
(B) [0, 2, 4]
(C) [0, 1, 2, 3, 4, 5]
(D) Runtime error


Answer: (B)

Explanation: The is statement checks whether the value lies in list data and if it does whether it’s divisible by 2. It does so for x in (0, 7).

Quiz of this Question

My Personal Notes arrow_drop_up
Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.