Python Dictionary
• Class 10
• Introduction to Python Dictionary
What is a Dictionary?
• A dictionary stores key-value pairs.
• Like a real dictionary:
• 'word' is the key, 'meaning' is the value.
• Example:
• student = {'name': 'Rahul', 'class': 10, 'marks': 92}
Key Features
• - Unordered (but keeps order in Python 3.6+)
• - Mutable
• - Keys are unique & immutable
Basic Operations
• Access: student['name']
• Add: student['age'] = 15
• Update: student['marks'] = 95
• Delete: del student['class']
Useful Methods
• student.keys(), student.values(), student.items()
• student.get('name')
Real-Life Example
• menu = {'burger': 50, 'pizza': 100, 'fries': 40}
• print('Pizza costs', menu['pizza'], 'rupees')
Recap
• ✅ Key-value pairs
• ✅ Use [] or get() to access values
• ✅ Easy to modify
• Keep practicing!