A dictionary connects each key to a value. Rather than asking for an item at a numbered position, we look up a value by its key. A colon separates each key from its value.
book = {"title": "Tides", "pages": 120, "available": True}
print(book["title"])
print(len(book))
print("pages" in book)
Tides
3
True
len counts key-value pairs. Membership checks keys, not values. Keys must be hashable: Python can use a hash value to find them efficiently, and their hash must remain stable while they are keys. Strings, integers, and tuples containing only hashable items are common choices; mutable lists and dictionaries cannot be keys. Values can be any type and can repeat. Keys are unique according to Python’s equality rules: for example 1 and True compare equal and refer to the same dictionary key.
labels = {"zone": "north", "zone": "south"}
print(labels)
{'zone': 'south'}
A later value for the same key replaces the earlier one. {} creates an empty dictionary. Keys should describe the identity of the entry: if two people share a name, using the name alone as a key would overwrite one person’s data.