Open In App

Python-Quizzes | Python Tuples Quiz | Question 9

Last Updated : 29 Sep, 2020
Like Article
Like
Save
Share
Report

Question 8: What is the output of the following program?




L = [2e-04, 'a', False, 87
T = (6.22, 'boy', True, 554
for i in range(len(L)): 
    if L[i]: 
        L[i] = L[i] + T[i] 
    else
        T[i] = L[i] + T[i] 
        break


(A) [6.222e-04, ‘aboy’, True, 641]
(B) [6.2202, ‘aboy’, 1, 641]
(C) TypeError
(D) [6.2202, ‘aboy’, False, 87]


Answer: (C)

Explanation: The for loop will run for i = 0 to i = 3, i.e. 4 times(len(L) = 4). 2e-04 is same as 0.0002, thus L[i] = 6.22 + 0.0002 = 6.2202. String addition will result in concatenation, ‘a’ + ‘boy’ = ‘aboy’. False + True is True, it’ll return the integer value of 1. As tuples are immutable, the code will end with TypeError, but elements of L will be updated.

Quiz of this Question
Please comment below if you find anything wrong in the above post


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads