自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

用Python字典刪除字典元素實際操作步驟

開發(fā) 后端
本文章主要介紹的是Python字典在計算機語言應用過程中,如何更新字典,以及刪除字典元素和字典所需要的相關實際應用方案。

如果你想了解Python字典相關應用方案,以及如何在Python字典中更新字典,以及如何刪除字典元素和字典的相關應用操作技巧,以下是相關內(nèi)容的具體介紹,希望你觀看完之后會有所收獲。

更新字典

采取覆蓋更新上例中

  1. dict2['name']='earth';  

更新

  1. dict2['name']='abc';  
  2.  

 

.刪除字典元素和字典

del dict2['name'] # 刪除鍵為“name”的條目dict2.clear() # 刪除dict2 中所有的條目del dict2 # 刪除整個dict2 字典dict2.pop('name') # 刪除并返回鍵為“name”的條目

 

  1. dict2 = {'name': 'earth', 'port': 80}  
  2. >>> dict2.keys()  
  3. ['port', 'name']  
  4. >>> 
  5. >>> dict2.values()  
  6. [80, 'earth']  
  7. >>> 
  8. >>> dict2.items()  
  9. [('port', 80), ('name', 'earth')]  
  10. >>> 
  11. >>> for eachKey in dict2.keys():  
  12. ... print 'dict2 key', eachKey, 'has value',
     dict2[eachKey]  
  13. ...  
  14. dict2 key port has value 80  
  15. dict2 key name has value earth  
  16.  

 

update()方法可以用來將一個字典的內(nèi)容添加到另外一個字典中

 

  1. {'server': 'http', 'port': 80, 'host': 'venus'}  
  2. >>> dict3.clear()  
  3. >>> dict3  
  4. >>> dict3  

以上的內(nèi)容就是對Python字典如何更新字典.以及如何刪除字典元素和字典的

【編輯推薦】

  1. Python編程版面在應用過程中的功能介紹我國IPTV研究目全球領先
  2. Python編輯器收藏的具體方案介紹
  3. Python統(tǒng)計如何進行DNA序列整理
  4. python svn腳本如何進行文件刪除
  5. Python 拼寫檢查如何更簡單的使用
責任編輯:佚名 來源: linux.chinaitlab.com
相關推薦

2010-03-24 13:04:12

Python嵌入

2010-04-15 14:30:35

Oracle創(chuàng)建

2010-03-12 15:29:19

Pythonexe

2010-04-21 15:52:45

Oracle游標

2010-04-20 11:06:33

Oracle索引

2010-06-01 15:54:46

MySQL-pytho

2010-07-02 11:10:56

SQL Server

2010-05-13 17:00:32

MySQL啟動方法

2010-07-21 15:22:07

2010-04-06 08:58:27

Oracle job

2010-05-12 13:45:25

Mysql 復制設置

2010-04-02 13:34:33

Oracle DBA

2010-03-16 18:19:41

Python函數(shù)

2010-06-11 13:13:38

訪問MySQL數(shù)據(jù)庫

2010-08-05 14:34:26

DB2存儲過程

2010-03-26 18:51:51

Python作用域

2010-03-24 18:00:30

Python中文轉(zhuǎn)換u

2010-03-19 11:18:07

Python讀寫配置文

2010-05-27 10:35:09

查詢MySQL數(shù)據(jù)

2010-04-15 13:51:06

Oracle EBS
點贊
收藏

51CTO技術(shù)棧公眾號