在 Python 中更新字典
pythonserver side programmingprogramming更新于 2025/4/5 13:00:17
您可以通过添加新条目或键值对、修改现有条目或删除现有条目来更新字典,如下面的简单示例 − 所示
示例
#!/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
相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

