Skip to content
Related Articles

Related Articles

Python-Quizzes | Python List Quiz | Question 22
  • Last Updated : 17 Sep, 2020
GeeksforGeeks - Summer Carnival Banner

Question 22: Find the output of the following program:




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) 

(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

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :