Home >>Python Dictionary Methods >Python Dictionary pop() Method

Python Dictionary pop() Method

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 Values

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
Here is an example of Python Dictionary pop() Method:

pers = {
"name": "rohan",
"model": "singh",
"year": 1995
}
pers.pop("model")
print(pers)

Output:
{'name': 'rohan', 'year': 1995}
Example 2:

pop1 = {'tab': 76, 'mob': 345, 'lap': 87, 'android': 22}   
pop2 = pop1.pop('tab')   
print(pop2)

Output:
76

No Sidebar ads