python pop函數的定義及使用方式(執行個體展示)

來源:互聯網
上載者:User
在這篇文章我們來瞭解關於python字典之中的 python pop函數的相關知識,在 python中的pop函數是什麼意思,這個函數有什麼作用都將會在接下來的文章之中得到解答。

python pop函數描述

Python 字典 pop() 方法刪除字典給定鍵 key 所對應的值,傳回值為被刪除的值。key值必須給出。 否則,返回default值。

文法

pop()方法文法:

pop(key[,default])

參數

key: 要刪除的索引值

default: 如果沒有 key,返回 default 值。

傳回值

返回被刪除的值。

python pop函數樣本

以下執行個體展示了 pop() 方法的使用方法:

#!/usr/bin/python# -*- coding: UTF-8 -*-site= {'name': '藍天白雲', 'alexa': 10000, 'url': 'www.runoob.com'}pop_obj=site.pop('name')print pop_obj    # 輸出 :藍天白雲


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.