Home  >  Article  >  Backend Development  >  How to add new content to dictionary in python

How to add new content to dictionary in python

尚
Original
2019-07-02 16:46:449296browse

How to add new content to dictionary in python

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn