How To Create A Dictionary In Python

In Python, a dictionary is an apparently random set of data values that may be used to store data values in the manner of a map. Unlike other data types, which can only store a single value as an element, dictionaries retain Key:value pairs instead of single values. The dictionary includes a key-value pair in order to make it more search engine optimized.

Creating a Dictionary in Python

A dictionary may be made in Python by enclosing a list of items in curly braces and separating them with commas. This will produce the dictionary. Dictionary stores values in pairs, with one value being referred to as the Key and the other matching pair element being referred to as the Key:value. In a dictionary, the values may be of any data type, and there can be many copies of each value, but the keys cannot be replicated and should be immutable.

Read: How to Create an executable from a Python program

Note: Dictionary keys are case sensitive; this means that keys with the same name but different case forms will be processed in various ways.

CODE:

Dict = {1: ‘This’, 2: ‘is’, 3: ‘Example’}

print (“\nDictionary with the use of Integer Keys: “)

print(Dict)

INPUT:

Read: How to use Yield in Python

OUTPUT:

 


If you like the content, we would appreciate your support by buying us a coffee. Thank you so much for your visit and support.

 

Nikolaus Oosterhof

Nikolaus holds a degree in software development and has a strong passion for all things tech-related, especially gadgets with screens. Though he is nostalgic for older phone models, he's a retired gamer and continues to enjoy programming in open-source environments. Additionally, Nikolaus enjoys writing about Linux, macOS and Windows and has experience designing web pages.

Leave a Reply