Dictionary Data Type

Last updated: Apr 12, 2026

Dictionary

Dictionary is a collection of key values, used to store data values like a map. The other data types which hold only a single value as an element. Dictionary holds the key:value pair. Key-Value is provided in the dictionary to make it more optimized. Dictionary is a collection which is ordered and mutable. No duplicate members.

Dict = {1: 'Liberation', 2: 'By', 3: 'Education'}
print(Dict)
{1: 'Liberation', 2: 'By', 3: 'Education'}

Creating a Dictionary: A dictionary can be created by placing a sequence of elements within curly {} braces, separated by 'comma'. Dictionary holds pairs of values, one being the Key and the other corresponding pair element being its key:value. Values in a dictionary can be of any data type and can be duplicated, whereas keys can't be repeated and must be immutable. Dictionary keys are case sensitive, the same name but different cases of Key will be treated distinctly.

Example:

# Creating a Dictionary with Integer Keys
Dict = {1: 'Liberation', 2: 'By', 3: 'Education'}
print("\nDictionary with the use of Integer Keys: ")
print(Dict)
 
# Creating a Dictionary with Mixed keys
Dict = {'Name': 'Libed', 1: [1, 2, 3, 4]}
print("\nDictionary with the use of Mixed Keys: ")
print(Dict)

Output:

Dictionary with the use of Integer Keys:
{1: 'Liberation', 2: 'By', 3: 'Education'}
 
Dictionary with the use of Mixed Keys:
{'Name': 'Libed', 1: [1, 2, 3, 4]}

Dictionary can also be created by the built-in function dict(). An empty dictionary can be created by just placing curly braces {}.

Example:

# Creating an empty Dictionary
Dict = {}
print("Empty Dictionary: ")
print(Dict)
 
# Creating a Dictionary with dict() method
Dict = dict({1: 'Liberation', 2: 'By', 3: 'Education'})
print("\nDictionary with the use of dict(): ")
print(Dict)
 
# Creating a Dictionary with each item as a Pair
Dict = dict([(1, 'Libed'), (2, 'Python')])
print("\nDictionary with each item as a pair: ")
print(Dict)

Output:

Empty Dictionary:
{}
 
Dictionary with the use of dict():
{1: 'Liberation', 2: 'By', 3: 'Education'}
 
Dictionary with each item as a pair:
{1: 'Libed', 2: 'Python'}