New: Complete Beginner's Guide to Coding is now available in Premium
Updated: Indian Govt Exam roadmaps now include salary breakdowns & timelines
Tip: Use the Career Hub to explore all career paths in one place
Tutorials Python Python Dictionaries

Python Dictionaries

Python

Dictionaries store data as key-value pairs. Think of it like a real dictionary — word (key) → meaning (value).

Key Points

  • Use curly braces {} with key: value pairs
  • Keys must be unique and immutable (strings, numbers)
  • Access values using dict[key] or dict.get(key)
  • Very fast lookups — used everywhere in real projects
  • Common methods: keys(), values(), items()
Example — PYTHON
# Creating a dictionary
student = {
    "name": "Rahul",
    "age": 20,
    "city": "Pune",
    "marks": 85
}
# Accessing values
print(student["name"])
print(student.get("city"))
# Adding / Updating
student["email"] = "[email]"
student["marks"] = 90
print(student)
# Looping through dictionary
for key, value in student.items():
    print(f"{key}: {value}")
# Dictionary of students
students = {
    "Rahul": 85,
    "Priya": 92,
    "Amit": 78
}
# Find topper
topper = max(students, key=students.get)
print(f"Topper: {topper} ({students[topper]} marks)")
# Check if key exists
if "Priya" in students:
    print(f"Priya scored {students['Priya']}")
Result
Rahul
Pune
{'name': 'Rahul', 'age': 20, 'city': 'Pune', 'marks': 90, 'email': '[email]'}
name: Rahul
age: 20
city: Pune
marks: 90
email: [email]
Topper: Priya (92 marks)
Priya scored 92