What is the Python popitem function? Example parsing

Source: Internet
Author: User
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 '}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.