Python Dictionaries
1. What is a Dictionary?
A dictionary is a collection of data stored as key : value pairs.
In simple words:
👉 A dictionary is like a real dictionary
-
Word → Meaning
-
Key → Value
2. Why Use Dictionary?
We use dictionary when:
-
Data has names (keys)
-
We want fast access to values
Example:
-
Student name → marks
-
Product name → price
3. Creating a Dictionary
Dictionaries use curly brackets { }.
Example
4. Access Dictionary Items
Use the key name to get value.
Example
5. Access Using get()
get() is safer because it does not give error.
Example
6. Change Dictionary Value
Example
7. Add New Item to Dictionary
Example
8. Remove Dictionary Items
Remove Using pop()
Remove Last Item (popitem())
Delete Using del
9. Loop Through Dictionary
Loop Keys
Loop Values
Loop Key & Value
10. Check if Key Exists
Example
11. Dictionary Length
Example
12. Dictionary with Different Data Types
Example
13. Common Beginner Mistakes
❌ Using Index Instead of Key
❌ Error.
❌ Accessing Missing Key
✔ Use:
14. Simple Practice Examples
Example 1: Product Dictionary
Example 2: Update Value
Example 3: Add Item
15. Summary (Python Dictionaries)
✔ Stores data in key-value form
✔ Keys are unique
✔ Values can change
✔ Fast and useful
✔ Very important in Python
📘 Perfect for Beginner eBook
This chapter is ideal for:
-
Python beginner books
-
School & college students
-
Self-learners
If you want next, I can write:
-
Access Dictionary Items
-
Change Dictionary Items
-
Dictionary Methods
-
Dictionary Exercises
Just tell me 😊
