CBSE Class 12 Computer Science Question 68 of 105

Python Revision Tour II — Question 17

Back to all questions
17
Question

Question 17

Though tuples are immutable type, yet they cannot always be used as keys in a dictionary. What is the condition to use tuples as a key in a dictionary ?

Answer

For a tuple to be used as a key in a dictionary, all its elements must be immutable as well. If a tuple contains mutable elements, such as lists, sets, or other dictionaries, it cannot be used as a key in a dictionary.