Dictionaries in python are used to store values in a format of key:value. It is ordered and changeable but does not allow any duplicates.
Syntax Of Dictionaries in Python:
Variable name={ Key: value key:value key:value }
For Example Of Dictionaries In Python:
dict1={ "Name":"lingarajtechhub" "UID":554412 "RID":"A" }
Here the values get stored as shown above and hence can be printed as:
Input:
dict={"Name":"Lingarajtechhub","UID":554412,"RID":"A"} print(dict)
Output:
We can also print the keys of the dictionaries individually as:
Input:
dict={"Name":"Lingarajtechhub","UID":554412,"RID":"A"} print(dict["Name"])
Output:
As the properties of the dictionaries suggest that they are changeable, let’s see an example to prove that they are changeable.
Input:
dict={"Name":"Lingarajtechhub","UID":554412,"RID":"A"} print(dict["UID"]) dict={"UID":554411} print(dict["UID"])
Output:
These were the example of dictionaries, we will deal more with them in the upcoming topics.
Hence, we come to the end of a short and sweet topic on dictionaries in python. Hope we were able to clear all your doubts.
Please share and comment this post and wants to improve this post WhatsApp us.