A dictionary is declared as: D = {10: "A", 25: "B", 32: "C", 54: "D"} Which of…
2023
A dictionary is declared as: D = {10: "A", 25: "B", 32: "C", 54: "D"} Which of the following is incorrect?
- A.
D[20] = "E"
- B.
D[30] += 20
- C.
D[32] += '*'
- D.
D['X'] = 100
Attempted by 1719 students.
Show answer & explanation
Correct answer: B
D[30] does not exist in the dictionary. Using += on a non-existent key raises a KeyError.