Constructing a python dictionary object using braces

Construct a Python dictionary object using braces and specifying the key-value pairs of the dictionary

Dictionary Updated 10 Sep 2016 1 min read

Overview

A Python dictionary object can be created by providing one or more key-value pairs which are separated by comma(s) inside a set of curly braces. The key value pairs themselves are separated by ":".

Example

python
# Example Python program that creates a

            # Python dictionary object using curly braces

            dictionaryObject = {"NASDAQ":102456,

                                "DOWJONES":134567,

                                "KOSPI":7892,

                                "Nikie": 8496};

            print("The stock indices:");

            print(dictionaryObject);

Output

Output
The stock indices:

            {'NASDAQ': 102456, 'DOWJONES': 134567, 'KOSPI': 7892, 'Nikie': 8496}