The del statement removes a key-value pair from a dictionary. For example, the following dictionary contains the names of various fruits and the number of each fruit in stock. If someone buys all of the pears, we can remove the entry from the dictionary.
Dictionaries are also mutable. As weβve seen before with lists, this means that the dictionary can be modified by referencing an association on the left hand side of the assignment statement. In the previous example, instead of deleting the entry for pears, we could have set the inventory to 0.
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: