Skip to content
beginner

Dictionaries in Python

Have you ever kept a list of names and phone numbers, or flipped through a glossary to find the meaning of a word? In both cases, you’re matching one piece…

Published 2026-05-11Updated 2026-05-126 min read

Have you ever kept a list of names and phone numbers, or flipped through a glossary to find the meaning of a word? In both cases, you’re matching one piece of information (like a name or a word) to something else (like a phone number or a definition). This idea of pairing things together is everywhere in daily life—and it’s just as useful in programming!

Python dictionaries make it easy to store and work with these kinds of key-value pairs in your code. In this article, you’ll discover what Python dictionaries are, why they’re so handy, and how you can use them to organize and access information quickly.


What Is a Python Dictionary?

A Python dictionary (or dict for short) is a built-in data structure that lets you store information as pairs: a key and a value. Think of a dictionary like a real-life address book. The key is the person’s name, and the value is their phone number. You look up the name (key) to find the number (value).

Unlike lists, which store items in a specific order and use numbers (indexes) to access them, dictionaries use keys—like words, names, or IDs—to access values. This makes dictionaries perfect for situations where you want to look up information quickly by a unique label.

Real-world analogy:

  • Contact list: Name → Phone number
  • Glossary: Word → Definition
  • Student records: Student ID → Grades

Python dictionaries are flexible and can store many different types of data, making them one of the most useful Python data structures for beginners and experts alike.


Why Use Dictionaries?

You might wonder, “Why not just use a list?” Here’s why Python dictionaries are often a better choice for certain tasks:

  • Quick lookup: With a dictionary, you can find a value instantly by its key, no matter how big your data is. Looking up a phone number by name is much faster than searching through a list.
  • Organized data: Dictionaries help you keep related information together. For example, you can store all details about a product (like name, price, and stock) in one place.
  • Real-world uses: Whenever you need to map one thing to another—like usernames to email addresses, product codes to descriptions, or countries to capitals—a dictionary is your go-to Python data structure.

Quiz Question 1

Question: Which of the following is the main advantage of using a Python dictionary over a list for storing data?

  • A) You can access values quickly using unique keys
  • B) Dictionaries use less memory than lists
  • C) Dictionaries automatically sort the data

How Dictionaries Store Data

At the heart of every Python dict are keys and values.

  • Key: The unique identifier you use to look up information (like a name, word, or ID).
  • Value: The data or information associated with that key (like a phone number, definition, or score).

You can think of a dictionary as a set of labeled boxes. Each label (key) points to something inside the box (value).

Common types for keys and values:

  • Keys are usually strings or numbers, and they must be unique within the dictionary.
  • Values can be any data type—numbers, strings, lists, even other dictionaries!

Example:
Imagine you want to store the ages of three friends:

ages = {
    "Alice": 25,
    "Bob": 30,
    "Charlie": 22
}

Here, "Alice", "Bob", and "Charlie" are keys, and their ages are the values.


Common Dictionary Operations

Let’s look at some basic things you can do with Python dictionaries:

  • Adding new key-value pairs:
    You can add a new item by assigning a value to a new key.

  • Changing values for existing keys:
    Update a value by assigning a new value to an existing key.

  • Removing items:
    Remove a key and its value using the del statement.

  • Checking if a key exists:
    See if a key is in the dictionary using the in keyword.

Quiz Question 2

Question: Which of these is a valid way to add a new key-value pair to a Python dictionary called ages?

  • A) ages["Sam"] = 27
  • B) ages.add("Sam", 27)
  • C) add(ages, "Sam", 27)
  • D) ages.append(["Sam", 27])

Everyday Examples of Dictionaries

Python dictionaries are everywhere once you know what to look for! Here are a few practical examples:

  • Storing contact information:
    Pair names with phone numbers.

  • Mapping product names to prices:
    Assign prices to product names.

  • Organizing quiz questions and answers:
    Match questions to their correct answers.

Whenever you need to pair up information—like matching questions to answers or products to prices—a Python dict is the perfect tool.


Tips for Beginners

Dictionaries are beginner-friendly, but here are a few tips to help you get started:

  • Keys vs. values:
    Remember, the key is what you use to look up information, and the value is the information itself.

  • Choose good key names:
    Use clear, descriptive keys (like "email" or "price") to make your code easy to read.

  • Keys must be unique:
    Each key in a dictionary must be different. If you try to add a key that already exists, the old value will be replaced.

  • Keys must be immutable:
    You can use strings, numbers, or tuples as keys, but not lists or other dictionaries.

  • Values can be anything:
    Values can be numbers, strings, lists, or even other dictionaries.

  • Order in dictionaries:
    In modern Python, dictionaries remember the order you add items, but you should not rely on this unless you specifically need it.


Practice and Next Steps

The best way to learn Python dictionaries is to use them! Here are some ideas to get you started:

  • Create your own dictionary:
    Try making a dictionary of your favorite movies and their release years.

  • Experiment:
    Add, update, and remove items. Check if certain keys exist. Print out all the keys and values.

  • Take a quiz:
    Test your understanding with the quiz questions in this article, or try some hands-on exercises.

  • Explore more:
    Once you’re comfortable, look into related topics like nested dictionaries (dictionaries inside dictionaries) or combining dictionaries with lists for more complex data structures.


Summary

Python dictionaries are a powerful and practical way to store and manage data as key-value pairs. They let you organize information in a way that’s easy to understand and super fast to use. As you continue your Python journey, you’ll find that dictionaries are one of the most important Python data structures you can master.

Keep practicing, experiment with your own examples, and soon you’ll be using Python dicts like a pro. Happy coding!


Quiz Answer Key

Question 1

Correct answer: A) You can access values quickly using unique keys

Explanation: Dictionaries let you look up values instantly by their keys, which is much faster than searching through a list.

Question 2

Correct answer: A) ages["Sam"] = 27

Explanation: You add a new key-value pair by assigning a value to a new key using square brackets. The other options are not valid ways to add items to a dictionary.

Keep learning

Related tutorials

Continue with nearby Python topics and beginner-friendly explanations.

beginner8 min read

Basic File I/O in Python

Learning to work with files is one of the most practical skills you can pick up as a beginner Python programmer. Whether you want to save your notes, read…

Read tutorial
beginner7 min read

Lists in Python

If you’ve ever wanted to keep track of a grocery list, a group of friends, or a collection of numbers, you already understand why storing multiple values…

Read tutorial