Locked lesson.
About this lesson
What is a dictionary and how do we use them?
Exercise files
Download this lesson’s related exercise files.
Dictionaries.docx59 KB Dictionaries - Solution.docx
59 KB
Quick reference
Dictionaries
A dictionary is a key/value paired list.
When to use
Use them when you have a list that's not numbered in nature.
Instructions
To create a dictionary:
fav_pizza = {
"John": "Pepperoni",
"Tim": "Mushroom",
"Mary": "Cheese"
}
To call an item from your dictionary, reference the key:
print(fav_pizza["John"])
Hints & tips
- Dictionaries contain key/value pairs
- Dictionaries are not numbered like lists
Lesson notes are only available for subscribers.