Python Dictionary
Key value pairs are important in coding. They are a great way to tie two related data elements together. A key is a constant that defies the data set while the value is the variable that belongs to the set. A common example of this could be name. Where “name” is the key and in this case “Michael” would be the value. These two data elements are intrinsically tied together once you set them to each other. In Python the syntax for this would look like:
In the example above, ‘name’ and ‘Michael’ are tied together as a key value pair. In order to call ‘Michael’ we could do use the ‘print’ method and use it to print out the value for our ‘name’ key. The syntax for this would look like:
By placing our key of ‘name’ in the square brackets, we are asking our print method to print out the associated value for our key. In this example the line of code above would print out ‘Michael’ since that is the value.
Manipulating dictionaries in Python:
The chart below copied from a great resource on the subject, available here shows us methods that we are able to use with dictionaries in Python. I highly suggest reading up on them at the link above and practicing them!