Question

1.
2.
3.
4.
Answer (Detailed Solution Below)

Option 3 : TypeError: unhashable type: 'list' / TypeError: unhashable type: 'list'

Advertisement

Detailed Solution

सही उत्तर TypeError: unhashable type: 'list' / TypeError: unhashable type: 'list' है।

Key Points
Helpful?
PrepSnapprepsnap.in • Part -A

Question:

What happens when the following Python code is executed? / निम्नलिखित Python कोड चलाने पर क्या होता है? d = {[1, 2]: 'a'}

1.
A dictionary is created successfully / डिक्शनरी सफलतापूर्वक बन जाती है
2.
The key is silently converted to a tuple / कुंजी चुपचाप टपल में बदल जाती है
3.
TypeError: unhashable type: 'list' / TypeError: unhashable type: 'list'
4.
KeyError / KeyError

Correct Answer: TypeError: unhashable type: 'list' / TypeError: unhashable type: 'list'

Dictionary keys must be hashable, and lists are mutable and unhashable, so using one as a key raises TypeError. / डिक्शनरी कुंजियाँ हैश करने योग्य होनी चाहिए; सूचियाँ परिवर्तनशील और अहैश करने योग्य हैं, अतः कुंजी के रूप में प्रयोग पर TypeError आता है।

Downloaded from PrepSnap (prepsnap.in)