Python Dictionary MCQs with answers Page - 8

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. What is the best way to remove all keys from a dictionary without deleting the dictionary?

  • (A) del dict
  • (B) dict = {}
  • (C) dict.clear()
  • (D) dict.removeAll()

A

Admin • 825.56K Points
Coach

Q. How would you check if a dictionary is empty?

  • (A) len(dict) == 0
  • (B) dict.empty()
  • (C) dict == None
  • (D) dict.length == 0

A

Admin • 825.56K Points
Coach

Q. What does `d.get('x', 'default')` return if 'x' is not a key?

  • (A) Error
  • (B) None
  • (C) False
  • (D) default

A

Admin • 825.56K Points
Coach

Q. Can a dictionary key be a tuple?

  • (A) Yes, if the tuple contains only immutable elements
  • (B) Yes, any tuple is allowed
  • (C) No, tuples are not hashable
  • (D) Only in Python 2

A

Admin • 825.56K Points
Coach

Q. Which method merges two dictionaries without modifying the originals (Python 3.9+)?

  • (A) d1 + d2
  • (B) merge(d1, d2)
  • (C) d1 | d2
  • (D) d1.append(d2)

A

Admin • 825.56K Points
Coach

Q. What will `max({1: 'a', 3: 'b', 2: 'c'})` return?

  • (A) 3
  • (B) 'b'
  • (C) Error
  • (D) None

A

Admin • 825.56K Points
Coach

Q. What will be the output of `sorted({'b': 2, 'a': 1})`?

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

A

Admin • 825.56K Points
Coach

Q. How would you access the last inserted key-value pair in a dictionary?

  • (A) dict.last()
  • (B) dict[-1]
  • (C) dict.popitem()
  • (D) dict.peek()
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