Can the keys of python dictionaries be the same?

silencement
Release: 2019-06-19 09:09:20
Original
4813 people have browsed it

Can the keys of python dictionaries be the same?

The same key is not allowed to appear twice in python. If the same key is assigned twice during creation, the latter value will be remembered, as shown in the following example:

dict1 = {'Name': 'Runoob', 'Age': 7, 'Name': '小菜鸟'}

print ("dict1['Name']: ", dict1['Name'])
Copy after login

If it is pycharm (community edition v3.4.4), pycharm will prompt: Dictionary contains duplicate keys 'Name' more...

actually prints the last value

Python's own idle will also print the last value A value

The above is the detailed content of Can the keys of python dictionaries be the same?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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!