In this article we learn about the Python Popitem function in the
python dictionary, what the
python popiteme function means, and what the function will do in the next article.
Description of the Python popiteme function
The Python Dictionary Popitem () method randomly returns and removes a pair of keys and values from the dictionary.
If the dictionary is already empty, but this method is called, the keyerror exception is reported.
Grammar
Popitem () method syntax:
Popitem ()
Parameters
No
return value
Returns a key-value pair (key,value) Form.
Python popiteme function instance
The following example shows how the Popitem () method is used:
#!/usr/bin/python#-*-coding:utf-8-*-site= {' name ': ' Rookie tutorial ', ' Alexa ': 10000, ' url ': ' Www.runoob.com '}pop_obj= Site.popitem () print (pop_obj) print (site)
The output is:
(' url ', ' www.runoob.com ') {' Alexa ': 10000, ' name ': ' \xe8\x8f\x9c\xe9\xb8\x9f\xe6\x95\x99\xe7\xa8\x8b '}