Correct option is B
Let's analyze each statement in relation to the dictionary D:
D = {10: "A", 25: "B", 32: "C", 54: "D"}
1.
(a) D[20] = "E": This is correct. You can add new key-value pairs to the dictionary. The key 20 does not exist in the dictionary, so it will be added with the value "E".
·
Updated Dictionary: {10: "A", 25: "B", 32: "C", 54: "D", 20: "E"}
2.
(b) D[30] += 20: This is
incorrect. The value associated with the key 30 doesn't exist in the dictionary, so attempting to increment it with += 20 will raise a KeyError. You can only perform operations like += on existing keys, where the value is a number (or string) that supports this operation.
3.
(c) D[32] += '*': This is correct. The value of D[32] is "C", which is a string. Using += '*' will append the character '*' to the existing value, resulting in "C*".
·
Updated Dictionary: {10: "A", 25: "B", 32: "C*", 54: "D"}
4.
(d) D["X"] = 100: This is correct. You can add new keys to the dictionary. In this case, the key "X" (a string) will be added with the value 100.
·
Updated Dictionary: {10: "A", 25: "B", 32: "C", 54: "D", "X": 100}
Important Key Points:
1. You can add new key-value pairs to a dictionary.
2. Operations like += can only be performed on keys that already exist and whose values support the operation.
3. Python dictionaries can have mixed types of keys (integers, strings, etc.).
Knowledge Booster:
·
Option (a): This is correct because adding new key-value pairs to a dictionary is valid in Python.
·
Option (c): This is correct because string concatenation using += is valid in Python.
·
Option (d): This is correct because adding a new key-value pair with a string key is valid.