Home >>Python Dictionary Methods >Python Dictionary pop() Method
Python Dictionary pop() Method in python dictionary is used to remove the specified element from the dictionary. It gives an error if the specified key is not present.
Syntax:dictionary.pop(keyname, defaultvalue)
Parameter | Description |
---|---|
keyname | It is Required. The keyname of the item you want to delete |
defaultvalue | It is Optional. if the specified key do not exist, default value is returned |
pers = {
"name": "rohan",
"model": "singh",
"year": 1995
}
pers.pop("model")
print(pers)
pop1 = {'tab': 76, 'mob': 345, 'lap': 87, 'android': 22}
pop2 = pop1.pop('tab')
print(pop2)