How to add new content to dictionary in python

Release: 2019-07-06 09:04:52
Original
9236 people have browsed it

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']
Copy after login

The output results are as follows :

dict['Age']:  8
dict['School']:  RUNOOB
Copy after login

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!