sounds = {"cat": "meow", "dog": "woof", "horse": "neigh"}
dog_sound = sounds["dog"]
horse_sound = sounds["horse"]
print("Dog goes", dog_sound)
print("Horse goes", horse_sound)
python dict.py
If we edit our script so that it asks for a key that doesn't exist, we will see an error being produced:
sounds = {"cat": "meow", "dog": "woof", "horse": "neigh"}
fish_sound = sounds["fish"]
print(fish_sound)
python dict.py