Introduction
Python is one of the most famous and used programming languages of the coding hub used on a server to create applications.
Here we will be discussing Python data type, i.e., Dictionary. Dictionary are one of the four built-in data types that store the data with different capabilities.

Dictionaries store the data like a map in the key: value pairs. Dictionary is represented by curly braces having keys and values.
Example:
Output
{‘Name’ : ‘Ashish’, ‘age’ : 20}
Ordered: The current version of the python language, i.e., python 3.7, dictionaries are ordered. This means that the defined order of the items will not change.
Changeable: This means we can modify or change the items after the dictionary has been created.
Does not allow duplicates: Here, this means that the two items cannot have the same key.
Python has provided some built-in functions to deal with dictionaries. Let's throw some light on them.
Python Dictionary inbuilt functions
get()
This function will return the value for the specified key. The syntax of this function will be:
dict1.get(key, value)
dict1: Name of the dictionary
Key: The name for which the value is to be returned.
Value: If the specified key is not found in the dictionary, the default value, i.e., None, will be returned.
Example
Input:
Output
20
If the key is not found in the dictionary, let's see the example.
Example
Input:
Output
None
keys()
This function returns a view object that displays a list of all the keys in the dictionary in order of insertion. The syntax of this function will be:
dictionary_name.keys()
It will return all the keys in a given dictionary in the same order as mentioned.
Example1
Input:
Output
dict_keys(['Name', 'section', 'Roll_no'])
Example2
We can update the dictionary after the insertion using the update function.
Input:
Output
Keys before Dictionary Updation:
dict_keys(['Name', 'section'])
dict_keys(['Name', 'section', 'Roll_no'])
copy()
This copy() function will create a copy of the original dictionary. The syntax of the function is as follows:
Dictionary_name.copy()
It will print the dictionary elements as it is mentioned.
Example
Input:
Output:
{'Name': 'Raj', 'section': 'B', 'Roll_no': 24}
items()
This function will return all the items, i.e., all the keys and the dictionary values.
The syntax of this method is as follows:
dictionary_name.items()
It will not take any parameters and return all the tuple pairs in a given dictionary.
Example
Input:
Output
dict_items([('Color1', 'Blue'), ('Color2', 'Green'), ('Color3', 'Red')])
Updated Dictionary will be:
dict_items([('Color1', 'Blue'), ('Color2', 'Green'), ('Color3', 'Red'), ('Color4', 'White')])
values()
This method returns a view object that contains the dictionary's values as a list. The syntax of this function will be:
dictionary_name.values()
It will return all the values in a given dictionary.
Example 1
Input:
Output
dict_values(['Ashish', '26', '5'])
Example 2
Input:
Output
1689
pop()
This function will remove the specified item from the dictionary. The syntax of the function is as follows:
dict1.pop(key, value)
dict1: Name of the dictionary
Key: The name of the item that is to be popped from the dictionary.
Value: If the specified key is not found in the dictionary, the default value, i.e., None, will be returned.
Example1
Input:
Output
{'Name': 'Ashish', 'Hello': '5'}
Example2
Input:
Output
5
update()
The update() function will insert the key: value pairs in the dictionary. The syntax of this function will be:
Dict1.update(iterable/dictionary)
The update() function parameters could be a dictionary or an iterable key-value pair to insert it in the dictionary.
Example
Input:
Output
{'Color1': 'White', 'Color2': 'Blue', 'Color3': 'Red', 'Color4': 'Black'}
fromkeys()
This function will return a dictionary with the specified keys and the specified values. The syntax for this method is as follows:
DICT.fromkeys(keys, value)
Keys: It specifies the keys of the new dictionary.
Value: Default value is none.
Example
Input:
Output
{'Color1': 0, 'Color2': 0, 'Color3': 0}
Example 2
Input:
Output
{'Color1': None, 'Color2': None, 'Color3': None}
clear()
This function will remove all the elements from the dictionary. The syntax for this will be:
dict1.clear()
It will not take any parameters and print an empty list.
Example
Input:
Output
{}
Must Read Python List Operations