Hello Everybody, and welcome to Hacoder. Today, we are going to discuss about Dictionary in Python.

If you have no knowledge of Python and still haven’t checked out our previous Python Tutorials, then click here.

So, without wasting time, lets get started!

Dictionary in Python:

Python dictionary is an unordered collection of items. In Dictionary, Each key is separated from its value by a colon (:), the items are separated by commas, and the whole thing is enclosed in curly braces.

An empty dictionary without any items is written with just two curly braces, like this: {}. Keys are unique within a dictionary while values may not be. The values of a dictionary can be of any type, but the keys must be of an immutable data type such as strings, numbers, or tuples.

Let’s take a look how Dictionary is created and accessed in Python.

The output of the above program will be:
{‘Hacoder’: ‘Discover the art of Coding and Hacking’, ‘Luka’: ‘Jack of all trades and master of them too’, ‘Webster’: ‘Creates awesome Python Tutorial’}
Creates awesome Python Tutorial

Updating Dictionary:

We can update an existing dictionary by adding a new entries, modifying an existing entry, or deleting an existing entry.

The output of this code is:
Python freak

Deleting Dictionary:

We can remove individual dictionary elements or clear the entire contents of a dictionary. We can also delete entire dictionary in a single operation.

That was all about Dictionary in Python. Learn more about Dictionaries in Python from the Official Python Documentation.

If you have any questions or suggestion, feel free to tell us in the comments section below.