Python Basics — Dictionaries

less than 1 minute read

Chapter 11 — Dictionaries

Dictionaries are Python’s most versatile data structure — they store data as key-value pairs and provide lightning-fast lookups O(1).

What You’ll Learn

Topic Page
Creating Dictionaries Creating Dictionaries →
Accessing & Modifying Accessing & Modifying →
Dictionary Methods Dictionary Methods →
Dictionary Comprehensions Dictionary Comprehensions →
Nested Dictionaries Nested Dictionaries →
Practice Exercises Practice Exercises →

Quick Preview

# Creating a dictionary
user = {
    "name": "Alice",
    "age": 30,
    "email": "alice@example.com"
}

# Accessing values
print(user["name"])       # Alice
print(user.get("phone"))  # None (safe access)

# Adding a new key
user["phone"] = "555-1234"

# Iterating
for key, value in user.items():
    print(f"{key}: {value}")

Key Properties

Property Description
Ordered Insertion order preserved (Python 3.7+)
Mutable Can add, modify, delete key-value pairs
Keys Must be hashable (strings, numbers, tuples)
Values Can be any type
Duplicates Keys must be unique; values can repeat

Start Learning: Creating Dictionaries →

Updated: