Python Dictionary Exercises
Exercise 1: Create a Dictionary
Question
Create a dictionary of a student and print it.
Solution
Exercise 2: Access Dictionary Item
Question
Print the value of "name" key.
Solution
Exercise 3: Safe Access Using get()
Question
Get the value of "marks" safely.
Solution
Exercise 4: Change Dictionary Value
Question
Change the age to 21.
Solution
Exercise 5: Add New Item
Question
Add "marks" with value 85.
Solution
Exercise 6: Remove Item Using pop()
Question
Remove "city" from dictionary.
Solution
Exercise 7: Loop Through Dictionary
Question
Print all keys and values.
Solution
Exercise 8: Check Key Exists
Question
Check if "phone" key exists.
Solution
Exercise 9: Count Dictionary Items
Question
Find how many items are in dictionary.
Solution
Exercise 10: Copy Dictionary
Question
Create a copy of dictionary and change the copy.
Solution
Exercise 11: Nested Dictionary
Question
Create a nested dictionary of two students.
Solution
Exercise 12: Access Nested Dictionary Item
Question
Print age of student "s2".
Solution
Exercise 13: Loop Nested Dictionary
Question
Print names of all students.
Solution
Exercise 14: Use setdefault()
Question
Add "country" key with default value.
Solution
Exercise 15: Clear Dictionary
Question
Remove all items from dictionary.
Solution
✅ Summary
✔ Dictionaries store key–value pairs
✔ Keys are unique
✔ Values can be changed
✔ Methods make work easy
✔ Practice improves skills
📘 Perfect for Beginner eBook
This exercise chapter is ideal for:
-
Python beginner books
-
School & college students
-
Self-learners
If you want next, I can write:
-
Mini Python Projects
-
File Handling
-
Functions (easy)
-
If–Else Exercises
Just tell me 😊
