Dictionary OperationsΒΆ

The del statement removes a key-value pair from a dictionary.

(ch12_dict4)

Dictionaries are also mutable.

(ch12_dict4a)

Similarily, a new shipment of 200 bananas arriving could be handled like this.

(ch12_dict5)

Notice that there are now 512 bananas—the dictionary has been modified. Note also that the len function also works on dictionaries. It returns the number of key-value pairs:

Next Section - Dictionary Methods