Python pop function definition and how to use it (example shows)

Source: Internet
Author: User
Tags function definition
In this article we learn about Python pop functions in Python dictionaries, what the pop function means in Python, and what this function does will be answered in the next article.

Python pop function description

The Python dictionary pop () method deletes the value of the dictionary given key key, and the return value is the deleted value. The key value must be given. Otherwise, the default value is returned.

Grammar

Pop () method syntax:

Pop (Key[,default])

Parameters

Key: The value to delete

Default: Returns the default value if there is no key.

return value

Returns the value that was deleted.

Python Pop Function Example

The following example shows how the Pop () method is used:

#!/usr/bin/python#-*-coding:utf-8-*-site= {' name ': ' Blue sky White Cloud ', ' Alexa ': 10000, ' url ': ' Www.runoob.com '}pop_obj=site.pop ( ' name ') print pop_obj    # output: Blue sky and white clouds


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.