Python-Quizzes | Python List Quiz | Question 22

Question 22: Find the output of the following program:

filter_none

edit
close

play_arrow

link
brightness_4
code

L1 = [1, 1.33, 'GFG', 0, 'NO', None, 'G', True
val1, val2 = 0, '' 
for x in L1: 
    if(type(x) == int or type(x) == float): 
        val1 +=
    elif(type(x) == str): 
        val2 +=
    else
        break
print(val1, val2) 

chevron_right


(A) 2 GFGNO
(B) 2.33 GFGNOG
(C) 2.33 GFGNONoneGTrue
(D) 2.33 GFGNO


Answer: (D)

Explanation: val1 will only have integer and floating values val1 = 1 + 1.33 + 0 = 2.33 and val2 will have string values val2 =’GFG’ + ‘NO’ = ‘GFGNO’. String ‘G’ will not be part of val2 as the for loop will break at None, thus ‘G’ will not be added to val2.

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.