["python"]
What is difference between pop() vs del for deleting a dictionary item? (python)

In Python there are at least two methods to delete an item from a dict using a key. d = {"keyA": 123, "keyB": 456, "keyC": 789} #remove via pop d.pop("keyA") #remove via del del d["keyB"] Both methods would remove the item from the dict. I wonder what the difference between these methods is and in what kinds of situations I should use one or the other.
d.pop(key) -- consider using this if you need the value for the item being deleted, and/or you want to specify a default value and don't want an exception raised if the key doesn't exist. e.g., value = d.pop(key, None) del key -- consider using this if you are certain that the key exists (or you expect an exception if it doesn't), and you don't need the value of the item being deleted. e.g., del key From the official Python language documentation: del d[key] Remove d[key] from d. Raises a KeyError if key is not in the map. pop(key[, default]) If key is in the dictionary, remove it and return its value, else return default. If default is not given and key is not in the dictionary, a KeyError is raised. https://docs.python.org/3/library/stdtypes.html#mapping-types-dict