Bird
Raised Fist0

Which of the following is the correct way to represent an inventory item with quantity in a dictionary in Python?

easy🧠 Conceptual Q3 of Q15
LLD - Design — Online Shopping Cart
Which of the following is the correct way to represent an inventory item with quantity in a dictionary in Python?
A{'item': 'apple', 'quantity': 10}
B['apple', 10]
C('apple', 10)
D'apple': 10
Step-by-Step Solution
Solution:
  1. Step 1: Identify dictionary syntax in Python

    Dictionaries use key-value pairs inside curly braces.
  2. Step 2: Check options for correct dictionary format

    {'item': 'apple', 'quantity': 10} uses keys and values properly with curly braces.
  3. Final Answer:

    {'item': 'apple', 'quantity': 10} -> Option A
  4. Quick Check:

    Dictionary syntax = {'item': 'apple', 'quantity': 10} [OK]
Quick Trick: Dictionaries use curly braces with key-value pairs [OK]
Common Mistakes:
MISTAKES
  • Using list or tuple instead of dictionary
  • Missing curly braces for dictionary

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes