Dictionary
Python dictionary data type and key-value pairs
Python Dictionary (or dict) is a type of data. Just like a string, int, float, list, etc. You can have a datatype called dictionary
. Its key characteristic is the well-known key:value
pair layout.
Think of these as mini vlookups in Excel. The key
refers to the item that you want to find, the value
refers to the data related to the key
. These are extremely helpful when you want to have a map that will return your information.
The keys in a dictionary must be unique. Values do not have to be unique. Keys and values are separated by a colon :
.
A dictionary is a type of mapper in python. That means you put something in, and something comes out.
ou can get creative with the data types you have as keys and values. Python can handle ints, strings and floats. Dictionary keys can not be lists.
Letβs take a look at a python dictionary code sample.
Link to code above