Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Dictionary basics
5. Accessing nonexistent dictionary elements
Dictionaries in loops and conditional statements
Dictionaries in functions
Summary

Instruction

Good job with accessing dictionary elements! A word of warning, though.

Be careful when you use keys within square brackets. If a key is not present in the dictionary, you will see a nasty error, and your code will crash. Let's see that in practice.

Exercise

Run the template code. We're trying to access a key that is not present in the dictionary.

As you can see, an error appears. We'll learn more about handling such situations in the next part of the course.