Question:

Which of the following data structures is used for storing key-value pairs in Python?

Show Hint

Dictionaries are a versatile data structure in Python, used to store data in a key-value pair format. Keys must be unique, and they map to specific values.
  • List
  • Dictionary
  • Tuple
  • Set
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is B

Solution and Explanation

Step 1: Understanding Python data structures.
In Python, a dictionary is a data structure that stores key-value pairs. Each key in a dictionary is unique and maps to a specific value.
Step 2: Evaluating the options.
  • (A) List: Incorrect. Lists are used to store ordered collections of items, but they do not store key-value pairs.
  • (B) Dictionary: Correct. Dictionaries are specifically used to store key-value pairs in Python.
  • (C) Tuple: Incorrect. Tuples are immutable sequences used to store collections of items, but they do not support key-value mapping.
  • (D) Set: Incorrect. Sets are unordered collections of unique elements, but they do not store key-value pairs.

Step 3: Conclusion.
The correct answer is (B) Dictionary, as it is used to store key-value pairs in Python. Final Answer:} Dictionary.
Was this answer helpful?
0
0