在 Python 中更新字典
您可以透過下面簡單示例中所示的方式新增新條目或鍵值對、修改現有條目或刪除現有條目來更新字典 −
示例
#!/usr/bin/python
dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}
dict['Age'] = 8; # update existing entry
dict['School'] = "DPS School"; # Add new entry
print "dict['Age']: ", dict['Age']
print "dict['School']: ", dict['School']輸出
執行上述程式碼時,會產生以下結果 −
dict['Age']: 8 dict['School']: DPS School
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP