🐍 Python Dictionaries for Beginners

📚 Table of Contents

  • What is a Dictionary?
  • Creating a Dictionary
  • Accessing Dictionary Values
  • Adding and Updating Data
  • Removing Dictionary Items
  • Dictionary Methods
  • Loop Through Dictionary
  • Practice Examples
  • FAQ

💡 Quick Tip

A dictionary stores data in key-value pairs. Use meaningful keys to make your code easy to understand.

⚠️ Common Mistakes

  • Using duplicate keys.
  • Accessing a key that does not exist.
  • Forgetting quotation marks around string keys.

✍️ By Roshni Code Charm

📅 July 2026 | ⏱️ 5 min read

🐍 What is a Dictionary?

A dictionary is a collection of data stored in key-value pairs. It is used to store information in an organized way.

Creating a Dictionary


student = {
    "name":"Roshni",
    "age":18,
    "course":"BCA"
}

print(student)

🔑 Accessing Dictionary Values

Values can be accessed using their keys.


student = {
"name":"Roshni",
"age":18
}

print(student["name"])

➕ Adding and Updating Data


student = {
"name":"Roshni"
}

student["age"] = 18

print(student)

➖ Removing Dictionary Items


student = {
"name":"Roshni",
"age":18
}

student.pop("age")

print(student)

✨ Dictionary Methods

🔄 Loop Through Dictionary


student = {
"name":"Roshni",
"age":18
}

for key,value in student.items():
    print(key,value)

🚀 Practice Example


mobile = {
"brand":"OnePlus",
"model":"Nord",
"year":2022
}

print(mobile["brand"])

❓ Frequently Asked Questions

1. What is a dictionary in Python?

A dictionary stores data using key-value pairs.

2. Are dictionaries ordered?

Yes, modern Python dictionaries maintain insertion order.

3. Can dictionary values be changed?

Yes, dictionaries are mutable and values can be updated.