In this article, we'll look at the dictionaries in Python, and in this article I'll explain
what the Python dictionary is . and explain
how the python dictionary is used . Well, don't say much nonsense, let's get into the article.
What is a python dictionary?
A dictionary is another mutable container model and can store any type of object.
Each key value of the dictionary is key=>value with a colon : split, with a comma, split between each key-value pair, and the entire dictionary is enclosed in curly braces {}, as shown in the following format:
D = {key1:value1, key2:value2}
The key is generally unique, and the value does not need to be unique if the last key value pair is repeated instead of the previous one.
>>>dict = {' A ': 1, ' B ': 2, ' B ': ' 3 '};>>> dict[' B '] ' 3 ' >>> dict{' a ': 1, ' B ': ' 3 '}
The value can take any data type, but the key must be immutable, such as a string, a number, or a tuple.
How does the Python dictionary work?
A simple Dictionary instance:
Dict = {' Alice ': ' 2341 ', ' Beth ': ' 9102 ', ' Cecil ': ' 3258 '}
You can also create a dictionary like this:
Dict1 = {' abc ': 456};d ict2 = {' abc ': 123, 98.6:37};