PRACTICE

Dictionary Lookups

Lesson notes

Your task

Create product with price 4. Update price to 5, then print the price and missing stock with a default of 0 on separate lines.

Expected output
5
0
Loading…

OUTPUT

Worked solution
product = {"price": 4}
product["price"] = 5
print(product["price"])
print(product.get("stock", 0))

Checks compare printed output, not your approach. Several solutions can be valid.

← Back to courses