Introduction
Another article which contains specific content about collection data type in Python programming language. There are several collection data types in Python programming language including list, tuple, dictionary and set among others. This article will discuss one of that collection data type. Specifically, it contain the discussion and also further description about dictionary. For more information about data types available in Python programming language, just check this link. Visiting that link, it will direct to an article with the title of ‘Data Type in Python’ as a reference and also information about the available data type in Python programming language.
Dictionary Characteristics
For dictionary as one of the collection data type available in Python programming language, the following are the characteristics of it :
-
Number of data.
It is obvious, as well as other collection data type, such as list and tuple, dictionary can store multiple data. As an example, dictionary with a multiple data will be as follow : {“id”:1,”Country”:’United States’,”Capital City”:”Washington D.C”,”Population”:329.5}
-
Data types.
As well as other collection data type, dictionary can store multiple data with various data type. The example is already exist as in the previous characteristic. But for just a reminder, it looks like the following : {“id”:1,”Country”:’United States’,”Capital City”:”Washington D.C”,”Population”:329.5}
The data above contains multiple data with various data type such as integer, string and also float.
-
Mutability.
As well as list, it has the availability to change the data available within. So, after adding the data into any data, it is possible to change the data along the way.
-
Initialization or Definition Format.
For defining the dictionary collection data type, it need a curly bracket to be able to do that. The example is already exist in the previous characteristic’s description. So, in order to initialize or to define it, just do it as follows :
dictionary_sample = {}
-
Data duplication.
It is not possible to have a duplicate value for the same key. Since dictionary is using string as key to pinpoint or to refer to the data, it is not possible to have duplicate data for the same key. The following is an example :
>>> dictionary_sample={"id":1,"id":1,"id":1,"country":"United States","country":"United States","Capital City":"Washington D.C"} >>> print(dictionary_sample); {'id': 1, 'country': 'United States', 'Capital City': 'Washington D.C'} >>> dictionary_sample={"id":1,"id":2,"id":3,"country":"United States","country":"United States","Capital City":"Washington D.C"} >>> print(dictionary_sample); {'id': 3, 'country': 'United States', 'Capital City': 'Washington D.C'} >>>