Python Dictionary MCQs with answers Page - 7

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 • 832.27K Points
Coach

Q. What is the output of `dict([(1, 2), (3, 4)])`?

  • (A) {1: 2, 3: 4}
  • (B) [1: 2, 3: 4]
  • (C) {(1, 2), (3, 4)}
  • (D) [(1, 2), (3, 4)]

A

Admin • 832.27K Points
Coach

Q. What will be the result of `mydict['missing']` if 'missing' is not a key?

  • (A) None
  • (B) 0
  • (C) Raises KeyError
  • (D) False

A

Admin • 832.27K Points
Coach

Q. What does `dict.clear()` do?

  • (A) Deletes the dictionary
  • (B) Clears all elements in the dictionary
  • (C) Returns the dictionary keys
  • (D) Returns None

A

Admin • 832.27K Points
Coach

Q. Can a dictionary contain another dictionary as a value?

  • (A) Yes
  • (B) No
  • (C) Only one level allowed
  • (D) Only if converted to JSON

A

Admin • 832.27K Points
Coach

Q. What does `d.popitem()` return?

  • (A) A key only
  • (B) A value only
  • (C) A tuple (key, value)
  • (D) A list of keys

A

Admin • 832.27K Points
Coach

Q. What will `dict.fromkeys('abc', 0)` return?

  • (A) {'a': 0, 'b': 0, 'c': 0}
  • (B) {'abc': 0}
  • (C) ['a', 'b', 'c']
  • (D) Error

A

Admin • 832.27K Points
Coach

Q. What happens when you use `update()` with overlapping keys?

  • (A) Raises Error
  • (B) Keeps old values
  • (C) Updates values with new ones
  • (D) Deletes duplicates

A

Admin • 832.27K Points
Coach

Q. Which function converts a dictionary to a JSON string?

  • (A) json.to_string()
  • (B) json.stringify()
  • (C) json.dumps()
  • (D) json.encode()

A

Admin • 832.27K Points
Coach

Q. Which of the following will cause a dictionary creation error?

  • (A) {'name': 'John'}
  • (B) {1: 'a', 2: 'b'}
  • (C) {[1, 2]: 'value'}
  • (D) {(1, 2): 'tuple'}

A

Admin • 832.27K Points
Coach

Q. How can you get a list of all values in a dictionary?

  • (A) dict.getvalues()
  • (B) dict.values()
  • (C) dict.vals()
  • (D) dict.all()
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