Does the dictionary pop() method return an error if the key is not present?



In this exercise, the pop() method is used to delete a key from a dictionary and the example shows that it is possible to specify a return value if the key isn’t present. Does an error occur if the key is not present and no default value is provided?


Yes, if the pop() method is called on a key that is not present in the dictionary and NO default value is provided in the pop() call, then the method will raise a KeyError exception.