Loading

Quipoin Menu

Learn • Practice • Grow

python / Dictionaries
tutorial

Dictionaries

A dictionary stores key‑value pairs. Keys are unique and immutable (strings, numbers, tuples), values can be any type. Dictionaries are unordered (though as of Python 3.7 they preserve insertion order). They are the primary mapping type in Python.

Creating Dictionaries
Use curly braces or the `dict()` constructor.


person = {"name": "Alice", "age": 25, "city": "New York"}
empty = {}
using_dict = dict(name="Bob", age=30)

Accessing Values
Use square brackets with the key, or `get()` (safer).


print(person["name"]) # Alice
print(person.get("country", "Unknown")) # Unknown

Adding/Modifying Items
Assign to a key to add or update.


person["email"] = "alice@example.com"
person["age"] = 26

Dictionary Methods
  • `keys()` – get all keys
  • `values()` – get all values
  • `items()` – get key‑value pairs
  • `pop(key)` – remove and return value
  • `update(other_dict)` – merge dictionaries
  • `clear()` – remove all items

for key, value in person.items():
print(key, value)
Two Minute Drill
  • Dictionaries store key‑value pairs with unique, immutable keys.
  • Access with `dict[key]` or `.get(key, default)`.
  • Keys can be added or updated by assignment.
  • Iterate over keys, values, or items with loops.
  • Widely used for mapping, caching, and configuration.

Need more clarification?

Drop us an email at career@quipoinfotech.com