Definition
The pop() method removes the specified item from the dictionary. The value of the removed item is the return value.
Syntax
dictionary.pop(keyname, defaultvalue)
Parameters
Parameter | Description |
---|---|
keyname | Required. The keyname of the item you want to remove |
defaultvalue | Optional. A value to return if the specified key do not exist. If this parameter is not specified, and the no item with the specified key is found, an error is raised |
Examples:
person = {
"name": "Raymond",
"age": 29,
"country": "Japan"
}
person.pop("age")
print(person)
# another example
person = {
"name": "Raymond",
"age": 29,
"country": "Japan"
}
j = person.pop("age")
print(j)