Dictionaries & Sets · Question 1 · Easy

A stationery shop updates its stock dictionary. What is printed?

stock = {"pen": 10, "book": 4}
stock["pen"] += 5
stock["bag"] = 1
print(len(stock), stock["pen"])
  1. 2 15
  2. 3 10
  3. 3 15
  4. 4 15
Answer and explanation

Answer: C. 3 15

Explanation: Assigning to an existing key updates its value, so pen becomes 15. Assigning to a new key adds an entry, so the dictionary now has 3 keys.

Next: get() is called for a key that is not in the dictionary, with and without a…

Practise dictionaries & sets

Try a fresh set of dictionaries & sets questions with an explanation after every answer, free and without signing up: Dictionaries & Sets practice. Or sit a full placement mock test.

More dictionaries & sets questions

More python practice

Conditions & Loops · Functions & Scope · Comprehensions & Generators · Classes & Objects · Exceptions & Files · Built-ins & Standard Library · Variables, Types & Operators · Python Strings

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge