DICTIONARY DATA TYPE


Dictionary Data Type

Dictionary is an unordered set of key-value pair items. It is defined with braces {} and is one of the most flexible data types built-in in python. It is like an associative array where each key stores a particular value. Dictionary keys can be only of primitive data type, whereas value can be of arbitrary Python objects.
Items in the Dictionary can be ordered, unordered, and changeable. But it does not permit duplicates.

About ordered and unordered:

If you use version 3.7 of Python, then all dictionaries are ordered. And in an earlier version or python version 3.6, dictionaries are unordered. The ordered dictionaries imply that all the items are arranged in a specified order, which is non-changeable.
The unordered dictionaries indicate that items are not arranged in an organized order, and you do not have to access any item by using an index.

What is changeable?

The dictionaries are changeable, which implies that we can change them accordingly. We can add or remove something after the creation of a dictionary.

Duplicates in dictionary:

In dictionaries, duplicates are not allowed. It implies that we cannot create more than one item with the same key.

Use of length function:

To know how many items a dictionary has, we can determine it using the len() function.

Datatypes in dictionary:

The data type in a dictionary can be of any type. It can be of boolean, string, and list data type.

type():

As a viewpoint of Python, dictionaries can be specified as objects and have the data type 'dict.'

Example:

x = dict(name="Knowledge2life", year=1) print(x)

OUTPUT:

{'name': 'Knowledge2life', 'year': 1}