6. Dictionaries
1. Simple Definition & Meaning
A Dictionary in Python is just like a real dictionary! In a real dictionary, you look up a word (the Key) to find its meaning (the Value). In Python, a dictionary stores Data in Key-Value pairs.
2. Real-World Examples
- Example 1: A phonebook! The person's name is the Key, and their phone number is the Value.
- Example 2: A restaurant menu. The food name is the Key, and the price is the Value.
3. Important Points
- Dictionaries are written with curly brackets
{}. - Example:
alien = {'color': 'green', 'points': 5}. - You get a value by using its key in square brackets:
alien['color'].
📝 Exam Notes (Quick Revision)
- Key-Value Pairs: Data is stored as
{key: value}. - Accessing:
dict_name[key]returns the value. - Adding:
dict_name[new_key] = new_value.