Home >Backend Development >Python Tutorial >What is the python popitem function? Example analysis
In this article, we will learn about the python popitem function in the python dictionary. What does the python popiteme function mean? What effect does this function have? Get the answer in the following article.
Description of python popiteme function
Python dictionary popitem() method randomly returns and deletes a pair of keys and values in the dictionary.
If the dictionary is already empty and this method is called, a KeyError exception will be reported.
Syntax
popitem()
Parameters
Return value
Returns a key-value pair (key, value) form.python popiteme function example
The following example shows how to use the popitem() method:#!/usr/bin/python # -*- coding: UTF-8 -*- site= {'name': '菜鸟教程', 'alexa': 10000, 'url': 'www.runoob.com'} pop_obj=site.popitem() print(pop_obj) print(site)The output result is:
('url', 'www.runoob.com') {'alexa': 10000, 'name': '\xe8\x8f\x9c\xe9\xb8\x9f\xe6\x95\x99\xe7\xa8\x8b'}The above is all the content of this article, the popitem function built into the dictionary in Python. I hope what I said and the examples I gave can be helpful to you. For more related knowledge, please visit the
Python tutorial column on the php Chinese website.
The above is the detailed content of What is the python popitem function? Example analysis. For more information, please follow other related articles on the PHP Chinese website!