You are here: Home / Topics / What is Dictionary in python

What is Dictionary in python

Filed under: Python on 2022-08-08 15:43:45

Python dictionary are the hash table type data. It arrangement are the two dimensional type or we can say each item contain two values ,one is key and another one is value corresponding to their key
Dictionary is the mutable data type
Each item in dictionary are separated by the comma(,) and enclosed in curly parentheses({}) and in each item key and their corresponding values are separated by colon (:) 
Example :- 
D1={1:'first',2:'second'}
D2={'one':'fisrt', 'two':'second'}

Program:-

d1={1:'first',2:'second'}
d2={'one':'fisrt', 'two':'second'}
print(d1)
print(d1[1])
print(d2['two'])
print(len(d1),len(d2))

Output-

{1: 'first', 2: 'second'}
first
second
2 2

In this program we display the dictionary in different ways. Firstly we display the whole dictionary and then we display the value of key '1' and then further we display the length of the dictionary.


About Author:
Y
Yogesh     View Profile
I am Yogesh Sharma. I found this website very useful for all the students. It is a very good website for learning thousands of multiple choice questions. Basically it is like a community website. Everyone can add questions so am I. I will add mcqs in this website to help you.