Computer Science

Python Dictionaries MCQs | 25 Practice Questions with Answers | CBSE Class 11 Computer Science

Class 11 · Computer Science

Python Dictionaries MCQs (25 Questions)

Practice these multiple-choice questions to strengthen your understanding of Python Dictionaries. Click Show Answer to reveal the correct answer and explanation.


Q1. A dictionary stores data in the form of:

A. Index and Value
B. Key and Value
C. Row and Column
D. Character and Number

Show Answer

Answer: B. Key and Value

Explanation: A dictionary stores data as key-value pairs.


Q2. Which symbol is used to create a dictionary in Python?

A. [ ]
B. ( )
C. { }
D. < >

Show Answer

Answer: C. { }

Explanation: Dictionaries are enclosed within curly braces.


Q3. Which of the following is a valid dictionary?

A. {"Name":"Aman","Marks":95}
B. [10,20,30]
C. (10,20,30)
D. {10,20,30}

Show Answer

Answer: A. {"Name":"Aman","Marks":95}

Explanation: Dictionaries contain key-value pairs separated by a colon (:).


Q4. Dictionary elements are accessed using:

A. Index numbers
B. Keys
C. Positions
D. Loops only

Show Answer

Answer: B. Keys

Explanation: Dictionary values are accessed using their corresponding keys.


Q5. Which statement about dictionary keys is correct?

A. Keys can be duplicated.
B. Keys must be unique.
C. Keys must be integers.
D. Keys cannot be strings.

Show Answer

Answer: B. Keys must be unique.

Explanation: Duplicate keys are not allowed in a dictionary.


Q6. Which function returns the number of key-value pairs in a dictionary?

A. size()
B. count()
C. len()
D. keys()

Show Answer

Answer: C. len()

Explanation: The len() function returns the total number of key-value pairs.


Q7. Which method returns all keys of a dictionary?

A. values()
B. items()
C. keys()
D. get()

Show Answer

Answer: C. keys()

Explanation: The keys() method returns a view of all keys.


Q8. Which method returns all values stored in a dictionary?

A. values()
B. keys()
C. items()
D. get()

Show Answer

Answer: A. values()

Explanation: The values() method returns all values stored in the dictionary.


Q9. Which method returns key-value pairs as tuples?

A. values()
B. keys()
C. get()
D. items()

Show Answer

Answer: D. items()

Explanation: The items() method returns all key-value pairs as tuples.


Q10. Which method safely returns the value of a key without generating an error if the key is absent?

A. index()
B. get()
C. find()
D. values()

Show Answer

Answer: B. get()

Explanation: The get() method returns None or a default value if the key does not exist.


Q11. Which method is used to update an existing dictionary or add new key-value pairs?

A. append()
B. update()
C. extend()
D. insert()

Show Answer

Answer: B. update()

Explanation: The update() method updates existing keys and adds new key-value pairs if they do not already exist.


Q12. Which method removes all key-value pairs from a dictionary?

A. remove()
B. delete()
C. clear()
D. pop()

Show Answer

Answer: C. clear()

Explanation: The clear() method removes all items from the dictionary.


Q13. Which method removes a specified key and returns its value?

A. popitem()
B. remove()
C. pop()
D. delete()

Show Answer

Answer: C. pop()

Explanation: The pop() method removes the specified key and returns its corresponding value.


Q14. Which method removes and returns the last inserted key-value pair?

A. pop()
B. popitem()
C. clear()
D. remove()

Show Answer

Answer: B. popitem()

Explanation: The popitem() method removes and returns the last inserted key-value pair.


Q15. Which loop is commonly used to traverse a dictionary?

A. switch
B. do-while
C. for loop
D. goto

Show Answer

Answer: C. for loop

Explanation: A for loop is commonly used to traverse dictionary keys and values.


Q16. Which operator checks whether a key exists in a dictionary?

A. ==
B. is
C. in
D. %

Show Answer

Answer: C. in

Explanation: The in operator checks whether a specified key exists in the dictionary.


Q17. Which statement about dictionary values is correct?

A. Values must always be unique.
B. Duplicate values are allowed.
C. Values must be integers only.
D. Values cannot be strings.

Show Answer

Answer: B. Duplicate values are allowed.

Explanation: Dictionary values can be repeated, but keys must be unique.


Q18. What is a nested dictionary?

A. A dictionary containing only numbers.
B. A dictionary inside another dictionary.
C. A dictionary with duplicate keys.
D. A dictionary containing only strings.

Show Answer

Answer: B. A dictionary inside another dictionary.

Explanation: A nested dictionary stores one or more dictionaries as values.


Q19. Which method is best suited for traversing both keys and values together?

A. keys()
B. values()
C. items()
D. get()

Show Answer

Answer: C. items()

Explanation: The items() method returns key-value pairs, making traversal easy.


Q20. Which statement about Python dictionaries is correct?

A. Dictionaries are immutable.
B. Dictionaries are ordered collections of key-value pairs and are mutable.
C. Dictionaries use numeric indexing only.
D. Dictionaries cannot be modified after creation.

Show Answer

Answer: B. Dictionaries are ordered collections of key-value pairs and are mutable.

Explanation: Modern Python dictionaries preserve insertion order and allow adding, updating, and deleting key-value pairs.


Q21. Which of the following statements is used to access the value associated with the key "Name" in the dictionary student?

A. student.Name
B. student("Name")
C. student["Name"]
D. student{Name}

Show Answer

Answer: C. student["Name"]

Explanation: Dictionary values are accessed using square brackets and the corresponding key.


Q22. What is the output of the following code?

student={
"Name":"Aman",
"Marks":90
}
print(student.get("City","Not Found"))

A. City
B. None
C. Not Found
D. Error

Show Answer

Answer: C. Not Found

Explanation: The get() method returns the specified default value when the key does not exist.


Q23. What is the output of the following code?

student={
"Name":"Aman",
"Marks":90
}
student["Marks"]=95
print(student["Marks"])

A. 90
B. 95
C. Error
D. None

Show Answer

Answer: B. 95

Explanation: Dictionaries are mutable, so the value associated with a key can be updated.


Q24. Which of the following can be used as a dictionary value?

A. List
B. Tuple
C. Dictionary
D. All of these

Show Answer

Answer: D. All of these

Explanation: A dictionary value can be of any valid Python data type, including lists, tuples, dictionaries, numbers, strings, and more.


Q25. Which of the following is the best real-life application of a Python dictionary?

A. Storing marks of students using roll numbers as keys
B. Storing only numbers in sequence
C. Creating multiplication tables
D. Printing star patterns

Show Answer

Answer: A. Storing marks of students using roll numbers as keys

Explanation: Dictionaries are ideal for storing and retrieving data using unique keys such as roll numbers, employee IDs, or product codes.


Answer Key

Q.No. Answer Q.No. Answer Q.No. Answer
1B 10B 19C
2C 11B 20B
3A 12C 21C
4B 13C 22C
5B 14B 23B
6C 15C 24D
7C 16C 25A
8A 17B
9D 18B

Practice Tips

  • Remember that dictionary data is stored as key-value pairs.
  • Keys must always be unique, whereas values may be repeated.
  • Practice using keys(), values(), items(), and get().
  • Understand the difference between pop() and popitem().
  • Use the in operator to check whether a key exists in a dictionary.
  • Practice traversing dictionaries using both for key in dictionary and for key, value in dictionary.items().
  • Attempt the questions without viewing the answers first, then use the explanations to strengthen your understanding.