Today I will be talking about dictionaries in python. Dictionaries use a key-value pair. For example I need the phone number of my friend Bob, I look up the name Bob and there’s his number. This is a good example of what dictionaries are used for but what do they look like?
Ex:
Dictionary = {“Dog”: “Puppy”, “Cat”: “Kitten”, “Duck”: “Duckling”}
print(Dictionary)
print(Dictionary[“Duck”])
Result:
{“Dog”: “Puppy”, “Cat”: “Kitten”, “Duck”: “Duckling”}
Duckling
Key-values pairs are separates by a colon and different pairs separated by comma. It doesn’t have to be string-string it can be string-integer, string-float, float-string, integer-integer, etc. You can print the entire dictionary or you can print a specific value by querying a key. As you can see from print(Dictionary[“Duck”]) I was able to print the value by utilizing its key.