5.1.4 Adding & Updating Entries: assignment & update()

Unit: Unit 5: Dictionaries and Sets • Interactive Practice

Quick Answer & Summary:

Interactive Python programming tutorial and practice in your browser.

Interactive Challenge (Run Live in Browser):

# Add new keys and update existing values
product = {
    "sku": "KB-900",
    "name": "Mechanical Keyboard",
    "price": 89.99
}

# 1. Update an existing key's value
product["price"] = 79.99

# 2. Add a brand new key-value pair
product["in_stock"] = True

# 3. Batch update multiple fields using .update()
product.update({"rating": 4.8, "warranty_months": 24})

print("Updated product:", product)
Open in Live Interactive Python Sandbox →