在字典中添加新的键?是否可以在Python字典创建之后添加密钥?它似乎没有.add()方法。
3 回答

一只甜甜圈
TA贡献1836条经验 获得超5个赞
d = {'key':'value'}print(d)# {'key': 'value'}d['mynewkey'] = 'mynewvalue'print(d)# {'mynewkey': 'mynewvalue', 'key': 'value'}

杨魅力
TA贡献1811条经验 获得超6个赞
>>> x = {1:2}>>> print x{1: 2}>>> d = {3:4, 5:6, 7:8}>>> x.update(d)>>> print x{1: 2, 3: 4, 5: 6, 7: 8}
添加回答
举报
0/150
提交
取消