Python‎ > ‎dict‎ > ‎

dict.pop()


Introduction
Return after removing the item from dictionary.

Syntax
dict.pop(x)

Parameters
x=key

Examples
The method remove the key and its corresponding value from dictionary.
 >>> dict={'Adil':49,'John':33}
>>> dict.pop('Adil')
49

The method remove the specific item from the dictionary and display the corresponding value.
 >>> 
>>> x=dict({'VA':3.1, 'DC':2,'NY':5.1, 'CA':4.4})
3.1
>>> x
{'DC': 2, 'NY': 5.1, 'CA': 4.4}
>>> x.pop("DC")
2
>>> x
{'NY': 5.1, 'CA': 4.4}
>>> x.pop('NY')
5.1
>>> x
{'CA': 4.4}
>>> x.pop('CA')
4.4
>>> x
{}
>>> 


Comments