We use subscript syntax to operate on a dictionary. Let’s add a value to our dictionary:
This updates the value of “Red” to 5. This does not add a new key-value pair to the dictionary because a value already exists for the key “Red” and keys in a dictionary are unique.
We also use subscript syntax to access values of the dictionary:
Finally, we can remove a key-value pair from the dictionary by assigning nil
to the key: