When you first start learning Python, chances are you write dictionary access as such:
dictionary['key']This is a valid way to retrieve the associated value in the dictionary, but it does come with a major drawback: what happens if the key doesn’t exist?
Take the following dictionary, for example:
cloud_information = {
"name" : "cumulonimbus",
"height" : "1000m",
"is_raining" : False
}Let’s say that I were to access the dictionary to get the name of the cloud:
dictionary["Height"]This will throw an error, as Height does not exist (but height does). The capitalization does matter and I’ll explain why below if you’d like a deeper dive into this topic.
Using the .get() method will help avoid this error and give us something to fall back on in case the key doesn’t exist in our dictionary. Generally, this is the preferred way of going about accessing dictionaries:

