Home  >  Article  >  Backend Development  >  Is python dictionary mutable?

Is python dictionary mutable?

(*-*)浩
(*-*)浩Original
2019-07-06 10:57:368155browse

Dictionary is another mutable container model and can store any type of object.

Is python dictionary mutable?

Each key-value key=>value pair in the dictionary is separated by colon :, and each key-value pair is separated by comma,. The entire dictionary includes In curly braces {}. (Recommended learning: Python video tutorial) The format of

is as follows:

d = {key1 : value1, key2 : value2 }

keys are generally unique, If the last key-value pair is repeated, it will replace the previous one, and the values ​​do not need to be unique.

>>>dict = {'a': 1, 'b': 2, 'b': '3'}
>>> dict['b']'3'
>>> dict{'a': 1, 'b': '3'}

The value can be of any data type, but the key must be immutable, such as a string, number, or tuple.

A simple dictionary example:

dict = {'Alice': '2341', 'Beth': '9102', 'Cecil': '3258'}

You can also create a dictionary like this:

dict1 = { 'abc': 456 }
dict2 = { 'abc': 123, 98.6: 37 }

For more Python related technical articles, please visit Python tutorial column for learning!

The above is the detailed content of Is python dictionary mutable?. 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