Python6 min read
Python Dictionaries
Store data in key-value pairs using dictionaries.
Emily Davis
December 18, 2025
0.0k0
Store related data together.
Create Dictionary
```python person = { "name": "Rachel", "age": 28, "city": "Houston" } ```
Access Values
```python print(person["name"]) # Rachel print(person.get("age")) # 28
Safe access (won't error) print(person.get("email", "Not found")) # Not found ```
Modify Dictionary
```python person = {"name": "Mark", "age": 25}
Add new key person["city"] = "Dallas"
Update existing person["age"] = 26
Remove key del person["age"]
print(person) # {'name': 'Mark', 'city': 'Dallas'} ```
Loop Through Dictionary
```python person = {"name": "Lisa", "age": 30, "city": "Phoenix"}
Loop through keys for key in person: print(key)
Loop through values for value in person.values(): print(value)
Loop through both for key, value in person.items(): print(f"{key}: {value}") ```
Remember
- Use dictionaries for related data - Keys must be unique - Use get() for safe access
#Python#Beginner#Dictionaries