How to add elements to the dictionary in python: You can directly add elements to the dictionary by giving a key-value pair, such as [aa['price'] = 100 aa['price'] = 100].
Method 1: Add directly, given key-value pair
(recommended tutorial: python video tutorial)
#pycharm aa = {'人才':60,'英语':'english','adress':'here'} print(aa) # {'人才': 60, '英语': 'english', 'adress': 'here'} #添加方法一:根据键值对添加 aa['价格'] = 100 aa['价格'] = 100 # {'人才': 60, '英语': 'english', 'adress': 'here', '价格': 100}
Method 2: Use the update method
#添加方法二:使用update方法添加 xx = {'hhh':'gogogo'} aa.update(xx) print(aa) # {'人才': 60, '英语': 'english', 'adress': 'here', '价格': 100, 'hhh': 'gogogo'}
Related recommendations: python tutorial
The above is the detailed content of How to add elements to dictionary in python. For more information, please follow other related articles on the PHP Chinese website!