The correct answer is:
B. The code is erroneous.
Explanation:
In the given code:
data = {'a': 1, 'b': 2, 'c': 3}
print(data['a', 'b'])
data is a dictionary with keys 'a', 'b', and 'c'.
When trying to access dictionary values, the key provided must be a single hashable object. In this case, ['a', 'b'] is a tuple (('a', 'b')), not a valid key in the dictionary.
Since the dictionary data does not contain the key ('a', 'b'), Python raises a KeyError.
Error:
KeyError: ('a', 'b')
You can't index with multiple keys like this. You get a KeyError.
upvoted 1 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
hovnival
1 month, 2 weeks agoFedeXD
4 months, 3 weeks ago