Definition and usage of python pop function (example demonstration)

乌拉乌拉~
Release: 2018-08-18 17:54:48
Original
9440 people have browsed it

In this article we will learn about the python pop function in the python dictionary. What does the pop function in python mean? What does this function do? All will be answered in the following articles.

python pop function description

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

Syntax

##pop() method syntax:

pop(key[,default])
Copy after login

Parameters

key: The key value to be deleted

default: If there is no key, return the default value.

Return value

Returns the deleted value.

Python pop function example

The following example shows how to use the pop() method:

#!/usr/bin/python
# -*- coding: UTF-8 -*-

site= {'name': '蓝天白云', 'alexa': 10000, 'url': 'www.runoob.com'}
pop_obj=site.pop('name')
print pop_obj    # 输出 :蓝天白云
Copy after login


The above is all about the pop 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 Definition and usage of python pop function (example demonstration). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template