🎓 All Courses | 📚 Python Programming Syllabus

📋 Study this course on TaskLoco
⚡ Key Concept #python-programming#dictionaries#data-structures

Dictionaries — Key-Value Storage

Dictionaries store data as key-value pairs. Ordered (Python 3.7+), mutable, no duplicate keys.


person = {
    "name": "Alice",
    "age": 30,
    "city": "New York"
}

Accessing values:

person["name"]           # "Alice"
person.get("age")        # 30
person.get("phone", "N/A")  # "N/A" (safe default)

Modifying:

person["age"] = 31          # update
person["email"] = "[email protected]" # add new key
del person["city"]          # delete key

Iterating:

for key in person:
    print(key)

for key, value in person.items():
    print(f"{key}: {value}")

Useful methods:

person.keys()    # all keys
person.values()  # all values
person.items()   # all key-value pairs
"name" in person # True (membership test)

YouTube • Top 10
Python Programming: Dictionaries
Tap to Watch ›
📸
Google Images • Top 10
Python Programming: Dictionaries
Tap to View ›

Reference:

Wikipedia: Associative Array

image for linkhttps://en.wikipedia.org/wiki/Associative_array

📚 Python Programming — Full Course Syllabus
📋 Study this course on TaskLoco

TaskLoco™ — The Sticky Note GOAT