Search⌘ K
AI Features

Solution: Contact book

Explore how to implement a contact book program in Python by using dictionaries to store and access contact details. Understand key-value pairs and how to retrieve information by keys, enabling you to build reusable and efficient data structures in your projects.

We'll cover the following...

This program stores contact information in a dictionary and then prints a specific phone number.

  • contacts is a dictionary — a collection of key–value pairs.

    • Each key (like "Mom" or "Pizza Place") is a label.

    • Each value (like "555-1234") is the information linked to that label.

  • To get a specific value, you use its key in square brackets:

Python
contacts = {
"Mom": "555-1234",
"Best Friend": "555-5678",
"Pizza Place": "555-9999"
}
print("Call Pizza Place at", contacts["Pizza Place"])