Python 字典 Dictionary pop() 方法
Python 字典 Dictionary pop() 方法
Python 字典 pop() 方法刪除字典給定鍵 key 及對(duì)應(yīng)的值,返回值為被刪除的值。key 值必須給出。 否則,返回 default 值。
語法
pop()方法語法:
pop(key[,default])
參數(shù)
- key: 要?jiǎng)h除的鍵值
- default: 如果沒有 key,返回 default 值
返回值
返回被刪除的值。
實(shí)例
以下實(shí)例展示了 pop() 方法的使用方法:
實(shí)例
#!/usr/bin/python # -*- coding: UTF-8 -*- site= {'name': '<a href="http://" target="_blank">碩編程</a>', 'alexa': 10000, 'url': 'www.codebaoku.com'} pop_obj=site.pop('name') print pop_obj # 輸出 :<a href="http://" target="_blank">碩編程</a>
相關(guān)文章
- Python 日期和時(shí)間
- Python 異常處理
- Python3 數(shù)字(Number)
- Python3 日期和時(shí)間
- Python MongoDB 數(shù)據(jù)庫連接 - PyMongo 驅(qū)動(dòng)
- Python ceil() 函數(shù)
- Python log10() 函數(shù)
- Python round() 函數(shù)
- Python File next() 方法
- Python os.minor() 方法
- Python os.mknod() 方法
- Python os.tcgetpgrp() 方法
- Python os.tmpfile() 方法
- Python isalnum()方法
- Python zfill()方法
- Python List cmp()方法
- Python List len()方法
- Python 字典 Dictionary update()方法
- Python time asctime()方法
- Python time gmtime()方法