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:

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 has a degree in software development. He is passionate about gadgets with a screen, nostalgic for phones, a retired gamer and open source programmer. He likes also to write about macOS and Windows. design web pages and debug long programs!

Leave a Reply