Python Tutoring Online
 Home

Python Dictionary Introduction

A Python dictionary is a built-in data structure used to store data in the form of key-value pairs. Each key is associated with a specific value, allowing Python programs to quickly retrieve and update data.

Dictionaries are extremely useful when working with structured data such as student records, configuration settings, JSON data, API responses, and database-like information.

Unlike lists, which use numeric indexes, dictionaries use keys to access values.

Syntax of a Python Dictionary

A dictionary is created using curly brackets { }. Each element contains a key and a value separated by a colon :. Multiple key-value pairs are separated by commas.

Python
student = {
"name": "Alice",
"age": 21,
"course": "Python"
}

print(student)

Output


{'name': 'Alice', 'age': 21, 'course': 'Python'}

In this example:

Example: Dictionary Representing Student Information

Dictionaries are often used to store structured records.

Python
student = {
"name": "John",
"age": 22,
"major": "Computer Science",
"university": "MIT"
}

print(student["name"])
print(student["major"])

Output


John
Computer Science

Example: Dictionary Storing Product Information

Python
product = {
"id": 101,
"name": "Laptop",
"price": 1200,
"in_stock": True
}

print(product)

Output


{'id': 101, 'name': 'Laptop', 'price': 1200, 'in_stock': True}

Key Characteristics of Python Dictionaries

1. Dictionaries Store Data as Key-Value Pairs

Each element in a dictionary consists of a key and its corresponding value.

Python
person = {
"name": "Sarah",
"city": "London"
}

print(person)

2. Keys Must Be Unique

Dictionary keys must be unique. If duplicate keys exist, Python keeps the last value assigned to that key.

Python
data = {
"name": "Alice",
"name": "Bob"
}

print(data)

Output


{'name': 'Bob'}

3. Dictionaries Are Mutable

Dictionaries can be modified after creation. You can update values, add new keys, or remove items.

Python
student = {
"name": "Alice",
"age": 21
}

student["age"] = 22

print(student)

Output


{'name': 'Alice', 'age': 22}

4. Dictionaries Are Ordered (Python 3.7+)

Modern versions of Python preserve the order of insertion. This means dictionary elements appear in the order they were added.

Python
data = {
"a": 1,
"b": 2,
"c": 3
}

print(data)

5. Dictionaries Can Store Multiple Data Types

Dictionary values can contain different data types such as numbers, strings, lists, or even other dictionaries.

Python
data = {
"name": "Alice",
"age": 21,
"skills": ["Python","SQL","Machine Learning"]
}

print(data)

Why Python Dictionaries Are Important

Python dictionaries are widely used in real programming tasks because they allow efficient lookup and structured data storage.

Next Steps

Now that you understand what a Python dictionary is, the next tutorial explains how to create dictionaries using different techniques.




Stuck Learning Python?

Struggling with Python syntax, assignments or debugging errors? Learning alone can be frustrating.

Get 1-on-1 Python tutoring and learn faster with clear explanations, real examples and live help.

    Get Python Tutoring

PythonTutor.net

Home    Tutorial     Online Live Trainings    Contact Us           © 2026 All rights reserved by www.PythonTutor.net