Tag Archives: #Master

Creation and use of dictionaries in Python

Dictionaries are all about keys and values. Each key is separated from its value by a colon (:), the items are separated by commas, and the whole thing is enclosed in curly braces. An empty dictionary without any items is written with just two curly braces, like this: {}.

Keys are unique within a dictionary while values may not be. The values of a dictionary can be of any type, but the keys must be of an immutable data type such as strings, numbers, or tuples.

Here’s a simple example of how to create dictionaries and how they run:

27

1014