Python – Add Dictionary Items

1. What Does “Add Dictionary Items” Mean?

Adding dictionary items means putting new key–value pairs into a dictionary.

In simple words:
👉 We add a new key with its value.

2. Add Item Using Key Name

The easiest way is using square brackets.

Example

student = {
"name": "Amit",
"age": 20
}

student["city"] = "Delhi"
print(student)

3. Add Item Using update()

update() can add one or many items.

Example (Add One Item)

student.update({"marks": 85})
print(student)

Example (Add Multiple Items)

student.update({
"phone": "1234567890",
"course": "Python"
})

print(student)

4. Add Item Only If Key Does Not Exist

Example

if "email" not in student:
student["email"] = "amit@email.com"

5. Add Items from Another Dictionary

Example

extra = {
"city": "Kolkata",
"country": "India"
}

student.update(extra)
print(student)

6. Add Items Using Loop

Example

keys = ["math", "science"]
values = [80, 90]

marks = {}

for k, v in zip(keys, values):
marks[k] = v

print(marks)

7. Common Beginner Mistakes

❌ Expecting Order

print(student)

Order is preserved in new Python versions, but beginners should not depend on order.

❌ Using Index Number

student[0] = "value"

❌ Wrong. Dictionaries use keys.

8. Simple Practice Examples

Example 1: Add Product Info

product = {"name": "Laptop"}
product["price"] = 50000
print(product)

Example 2: Add Country

person = {"name": "Ravi"}
person.update({"country": "India"})
print(person)

Example 3: Add Marks

marks = {}
marks["english"] = 75
marks["math"] = 85
print(marks)

9. Summary (Add Dictionary Items)

✔ Add items using key name
update() adds one or many items
✔ Keys must be unique
✔ Values can be any data type
✔ Very useful in real programs

📘 Perfect for Beginner eBook

This chapter is ideal for:

  • Python beginner books

  • School & college students

  • Self-learners

If you want next, I can write:

  • Remove Dictionary Items

  • Loop Dictionaries

  • Dictionary Methods

  • Dictionary Exercises

Just tell me 😊

You may also like...