性夜影院午夜看片,无码精品久久一区二区三区,婷婷成人丁香五月综合激情,校园春色 qvod,性调教室高h学校

如何刪除字典元素?【每日一個知識點第189期-Python】

能刪單一的元素也能清空字典,清空只需一項操作。

顯示刪除一個字典用del命令,如下實例:

#!/usr/bin/Python3

dict = {'Name': 'Runoob', 'Age': 7, 'Class': 'First'}

del dict['Name'] # 刪除鍵 'Name'
dict.clear()     # 清空字典
del dict         # 刪除字典

print ("dict['Age']: ", dict['Age'])
print ("dict['School']: ", dict['School'])

 

但這會引發(fā)一個異常,因為用執(zhí)行 del 操作后字典不再存在:

Traceback (most recent call last):
  File "test.py", line 9, in <module>
    print ("dict['Age']: ", dict['Age'])
TypeError: 'type' object is not subscriptable

 

注:del() 方法后面也會討論。


Python入門每日一個知識點》欄目是馬哥教育Python年薪20萬+的學員社群特別發(fā)起,分享Python工具、Python語法、Python項目等知識點,幫助大家快速的了解Python學習,快速步入Python高薪的快車道。

http://www.vfte.cn/73198.html

相關新聞

歷經(jīng)多年發(fā)展,已成為國內(nèi)好評如潮的Linux云計算運維、SRE、Devops、網(wǎng)絡安全、云原生、Go、Python開發(fā)專業(yè)人才培訓機構!