The way to add new content to the dictionary is to add new key/value pairs, modify or delete existing key/value pairs, as shown in the following example:
#!/usr/bin/python dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'} dict['Age'] = 8 # 更新 dict['School'] = "RUNOOB" # 添加 print "dict['Age']: ", dict['Age'] print "dict['School']: ", dict['School']
The output results are as follows :
dict['Age']: 8 dict['School']: RUNOOB
For more Python-related technical articles, please visit the Python Tutorial column to learn!
The above is the detailed content of How to add new content to dictionary in python. For more information, please follow other related articles on the PHP Chinese website!