Advertisements
Advertisements
प्रश्न
If my_dict is a dictionary as defined below, then which of the following statements will raise an exception?
my_dict = {'apple': 10, 'banana': 20, 'orange': 30}
विकल्प
my_dict.get('orange')
print(my_dict['apple', 'banana'])
my_dict['apple']=20
print(str(my_dict))
MCQ
उत्तर
print(my_dict['apple', 'banana'])
Explanation:
The code attempts to access a dictionary key via a tuple ('apple', 'banana') rather than separate keys. This key doesn't exist, resulting in a KeyError.
shaalaa.com
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?