Python Dictionary - Dictionary in Python - JSON like structure

Dictionary is one of the most important types of data types in Python programming language and it has a structure similar too that of JSON Structure which makes it very useful for storing data.

In other programming languages, they are found as associative arrays  or associative memories. 

Python dictionaries are indexed by keys which must be of immutable type - such  as strings, numbers, or must contain immutable data typle if they are of collection type such as tuples.

Dictionaries can be seen in the form of key: value pairs wherein keys must be unique in the same dictionary and is enclosed by curly brackets.

JSON module always produces str objects.

JSON always has double quotes while python dictionary dic can have either of the types of quotes.

 

How to create a new dictionary in python?

To create a blank dictionary, all you have to do is to type {}.

Every dictionary is enclosed by the curly brackets.

To create a basic dictionary, you can follow following steps:

NEWDICT =  {}   #Creates a blank dictionary with the identifiable name NEWDICT which can be anything you want.

NEWDICT = {'key1':'value1'} #This is the basic dictionary with one key value pair -- both key and value must be inside quotes. 

Language: 
Language: