Constructing A Python Dictionary Object Using Braces

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:

# 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:

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

 


Copyright 2023 © pythontic.com