Python-Quizzes | Python List Quiz | Question 16

Question 16: Find the output of the following program:

filter_none

edit
close

play_arrow

link
brightness_4
code

data = [2, 3, 9
temp = [[x for x in[data]] for x in range(3)] 
print (temp) 

chevron_right


(A) [[[2, 3, 9]], [[2, 3, 9]], [[2, 3, 9]]]
(B) [[2, 3, 9], [2, 3, 9], [2, 3, 9]]
(C) [[[2, 3, 9]], [[2, 3, 9]]]
(D) None of these


Answer: (A)

Explanation: [x for x in[data] returns a new list copying the values in the list data and the outer for statement prints the newly created list 3 times.

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.