Wednesday, September 9, 2026
Home Academic Creating dictionary in Python

Creating dictionary in Python

A Dictionary is an unordered set of key:value pairs, with the requirement that the keys are unique (within a Dictionary). A few pointers about dictionary:

  • An empty dictionary can be created by a pair of braces: {}.
  • Dictionary elements can be accessed by dictionary keys
  • DICT.keys() will return all the keys of given dictionary “DICT”

DICT = {
'Name':'Kunal',
'Company':'Analytics Vidhya'
}

#Dictionary elements can be accessed by keys

print (DICT['Name'])

#The above print statement will print Kunal

In dictionary “DICT”, Name and Company are dictionary keys whereas “Kunal” and “Analytics Vidhya” are their respective values.

Other Tasks:

# Create a dictionary dict1
dict1 = { ‘Age’: 16, ‘Name’: ‘Max’, ‘Sports’: ‘Cricket’}

# Update the value of Age to 18
dict1[‘Age’] = 18

# Print the value of Age
print(dict1[‘Age’])

# Store the keys of dictionary dict1 to dict_keys
dict_keys = dict1.keys()

Try it yourself in DataCamp here

datasagarhttp://www.DataSagar.com
Sagar is multidisciplinary technologist, educator, and entrepreneur based in Nepal. As the founder of Illionso Technologies and Kashi Garden Resort, he operates at the intersection of web architecture, data intelligence, innovation, and digital transformation. From building digital solutions to scaling real-world concepts, his mission is to share knowledge alongside merge emerging as well as disruptive technologies with transformative offline experiences.
RELATED ARTICLES

Most Popular