ReferenceDictionary methods
dict.pop()
Removes a key and returns its value.
Signature
mapping.pop(key, default=...)Parameters
| Name | Means |
|---|---|
key | what to remove |
default | returned instead of raising when it is missing |
Returns
The value. Raises KeyError with no default.
Example
Python
person = {"name": "Ada", "tmp": 1}
print(person.pop("tmp"))
print(person)
print(person.pop("missing", "not there"))Output
1
{'name': 'Ada'}
not there