Open In App
Related Articles

Python-Quizzes | Python Tuples Quiz | Question 2

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report
Question 2: What is the output of the following program?
tuple = {} 
tuple[(1,2,4)] = 8
tuple[(4,2,1)] = 10
tuple[(1,2)] = 12
_sum = 0
for k in tuple
    _sum += tuple[k] 
print(len(tuple) + _sum) 

                    
(A) 30 (B) 31 (C) 32 (D) 33

Answer: (D)

Explanation: Tuples can be used for keys into a dictionary. The tuples can have mixed lengths and the order of the items in the tuple is considered when comparing the equality of the keys.

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

Last Updated : 18 Sep, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads