Python Dictionary MCQs with answers Page - 2

You will find multiple-choice questions (MCQs) related to #Python Dictionary here. Go through these questions to prepare effectively for your upcoming exams and interviews.

To view the correct answer for any question, simply click the "Show Answer" button.

Have a question to share? Click on "Add Question" to contribute!

A

Admin • 825.56K Points
Coach

Q. Which of the following will raise a TypeError?

  • (A) my_dict = {[1, 2]: 'value'}
  • (B) my_dict = {1: 'value'}
  • (C) my_dict = {True: 'yes'}
  • (D) my_dict = {(1, 2): 'tuple'}

A

Admin • 825.56K Points
Coach

Q. What does `dict1 == dict2` check?

  • (A) Memory location
  • (B) If they are the same object
  • (C) If both have the same keys and values
  • (D) Always False

A

Admin • 825.56K Points
Coach

Q. What will `dict([(1, 'a'), (2, 'b')])` return?

  • (A) {1: 'a', 2: 'b'}
  • (B) [(1, 'a'), (2, 'b')]
  • (C) {(1, 'a'), (2, 'b')}
  • (D) Syntax Error

A

Admin • 825.56K Points
Coach

Q. Can dictionary values be duplicated?

  • (A) Yes
  • (B) No
  • (C) Only strings
  • (D) Only numbers

A

Admin • 825.56K Points
Coach

Q. What does `dict.keys()` return?

  • (A) A list of keys
  • (B) A view object of keys
  • (C) A list of values
  • (D) A tuple of keys

A

Admin • 825.56K Points
Coach

Q. Which of these can be used to loop through a dictionary?

  • (A) `for i in dict`
  • (B) `for i in dict.items()`
  • (C) `for i in dict.keys()`
  • (D) All of the above

A

Admin • 825.56K Points
Coach

Q. Which data type is returned by `dict.items()`?

  • (A) List
  • (B) Tuple
  • (C) View
  • (D) Set

A

Admin • 825.56K Points
Coach

Q. What is the output of `dict(zip(['a', 'b'], [1, 2]))`?

  • (A) {'a': 1, 'b': 2}
  • (B) [('a', 1), ('b', 2)]
  • (C) {1: 'a', 2: 'b'}
  • (D) Error

A

Admin • 825.56K Points
Coach

Q. What happens if you delete a key that doesn't exist using `del`?

  • (A) Returns False
  • (B) Returns None
  • (C) Does nothing
  • (D) Raises KeyError

A

Admin • 825.56K Points
Coach

Q. What is a dictionary in Python?

  • (A) An ordered collection of elements
  • (B) An unordered collection of key-value pairs
  • (C) A mutable list of strings
  • (D) A sequence of characters
What's Tag

As you may know, questions are organized under broad categories. Each category can include various types of questions. For example, the "History" category might contain questions about the Revolt of 1857, Shivaji Maharaj, Ancient History, Buddhism, and more.

To further refine this organization, we've introduced tags, which act as sub-categories to group questions more specifically.

Verified users can add tags to any question. If you have any suggestions regarding this system, we'd love to hear from you. Contact Us

Learn More