📘 Lesson 7: Dictionaries & Advanced Structures
Dictionaries in Python allow you to store data using key-value pairs. They're very useful for organizing data that has labels.
📌 What You'll Learn
- How to define and use dictionaries
- Accessing, updating, and deleting values
- Looping through dictionaries
- Working with nested dictionaries/lists
🔤 Example
student = {
"name": "Ali",
"age": 16,
"grades": [85, 90, 92]
}
print(student["name"]) # Ali
student["age"] = 17 # Update value
student["city"] = "Istanbul" # Add new key-value pair
for key in student:
print(key, ":", student[key])
📝 Your Turn: Assignment
Create a dictionary-based contact book! Here's what it should do:
- Ask the user for a name and phone number
- Store them in a dictionary
- Allow the user to enter multiple contacts
- Print all contacts at the end
Advanced idea: Use a loop and let the user type "done" when they want to stop.
← Back to Dashboard