python中怎么向字典添加元素
时间:2020-10-20 09:52
python中向字典添加元素的方法:可以通过给定键值对直接向字典中添加元素,如【aa['价格'] = 100 aa['价格'] = 100】。 方法一:直接添加,给定键值对 (推荐教程:python视频教程) 方法二:使用update方法 相关推荐:python教程 以上就是python中怎么向字典添加元素的详细内容,更多请关注gxlsystem.com其它相关文章!#pycharm
aa = {'人才':60,'英语':'english','adress':'here'}
print(aa) # {'人才': 60, '英语': 'english', 'adress': 'here'}
#添加方法一:根据键值对添加
aa['价格'] = 100
aa['价格'] = 100 # {'人才': 60, '英语': 'english', 'adress': 'here', '价格': 100}
#添加方法二:使用update方法添加
xx = {'hhh':'gogogo'}
aa.update(xx)
print(aa) # {'人才': 60, '英语': 'english', 'adress': 'here', '价格': 100, 'hhh': 'gogogo'}