Python Dictionary MCQs with answers Page - 3

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 is the correct way to define a dictionary?

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

A

Admin • 825.56K Points
Coach

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

  • (A) 1
  • (B) 2
  • (C) 3
  • (D) Error

A

Admin • 825.56K Points
Coach

Q. Which method is used to get the value from a dictionary for a given key?

  • (A) value()
  • (B) get()
  • (C) keys()
  • (D) items()

A

Admin • 825.56K Points
Coach

Q. What will `my_dict = {'a':1}; my_dict['b']` return?

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

A

Admin • 825.56K Points
Coach

Q. Which method adds a new key-value pair to a dictionary?

  • (A) add()
  • (B) append()
  • (C) insert()
  • (D) assignment using [ ]

A

Admin • 825.56K Points
Coach

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

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

A

Admin • 825.56K Points
Coach

Q. Which method removes all items from a dictionary?

  • (A) delete()
  • (B) remove()
  • (C) clear()
  • (D) discard()

A

Admin • 825.56K Points
Coach

Q. What will `my_dict = {'a': 1}; 'a' in my_dict` return?

  • (A) False
  • (B) True
  • (C) None
  • (D) KeyError

A

Admin • 825.56K Points
Coach

Q. How can you get all the keys from a dictionary?

  • (A) dict.keys()
  • (B) dict.getkeys()
  • (C) dict.allkeys()
  • (D) dict.keySet()

A

Admin • 825.56K Points
Coach

Q. Which method returns all key-value pairs in a dictionary?

  • (A) items()
  • (B) pairs()
  • (C) values()
  • (D) entries()
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