Learn Python Dictionary with Detail Explanation and Example

dictionary is an unordered collection of data in a key: value pair.

Because limitations of the list, list is not enough to represent real-life data.

there are two ways to create a dictionary in python.

1. using curly brackets ‘{}’ 2. using dict() function

To create a dictionary in python write comma-separated data in form of a key: value pair inside the curly bracket.

You can also use the dict() function to create a dictionary in python. let’s see this with the help of an example.

With the help of keys, you can access the data of a dictionary

and you can also use the .get() method to access data from the dictionary

yash  unknown  20

You can store anything (number, string, list, dictionary, tuple) inside a dictionary.

{}  {'name': 'harshit', 'age': 25}