Question

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

Option 1 : d['c'] raises KeyError because 'c' is not a key in d / d['c'] KeyError देता है क्योंकि 'c', d में कुंजी नहीं है

Advertisement

Detailed Solution

सही उत्तर d['c'] raises KeyError because 'c' is not a key in d / d['c'] KeyError देता है क्योंकि 'c', d में कुंजी नहीं है है।

Key Points
Helpful?
PrepSnapprepsnap.in • Part -A

Question:

The following code raises an error. Which statement best explains the cause? / निम्नलिखित कोड त्रुटि उत्पन्न करता है। कौन-सा कथन कारण को सबसे अच्छी तरह समझाता है? d = {'a': 1, 'b': 2} print(d['a'] + d['c'])

1.
d['c'] raises KeyError because 'c' is not a key in d / d['c'] KeyError देता है क्योंकि 'c', d में कुंजी नहीं है
2.
d['a'] raises KeyError because 'a' is missing / d['a'] KeyError देता है क्योंकि 'a' अनुपस्थित है
3.
dictionaries cannot store integer values / शब्दकोश पूर्णांक मान नहीं रख सकते
4.
print cannot display dictionary values / print शब्दकोश मान नहीं दिखा सकता

Correct Answer: d['c'] raises KeyError because 'c' is not a key in d / d['c'] KeyError देता है क्योंकि 'c', d में कुंजी नहीं है

Accessing a missing key with square brackets raises KeyError: 'c'. Using d.get('c', 0) would have avoided it. / वर्ग कोष्ठक से अनुपस्थित कुंजी माँगने पर KeyError: 'c' मिलता है। d.get('c', 0) से यह बच जाता।

Downloaded from PrepSnap (prepsnap.in)