Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Python-Quizzes | Python Tuples Quiz | Question 2

  • Last Updated : 18 Sep, 2020

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

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!