Python Dictionary MCQs with answers Page - 4

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. Dictionaries in Python are:

  • (A) Immutable
  • (B) Ordered since Python 3.7
  • (C) Unordered always
  • (D) Not iterable

A

Admin • 825.56K Points
Coach

Q. What does `dict.pop('key')` do?

  • (A) Removes and returns the value for 'key'
  • (B) Deletes the key only
  • (C) Removes all keys
  • (D) Raises an error always

A

Admin • 825.56K Points
Coach

Q. What will happen if you assign a value to an existing key?

  • (A) It creates a duplicate key
  • (B) It updates the value
  • (C) It throws an error
  • (D) It deletes the key

A

Admin • 825.56K Points
Coach

Q. Which of the following is not a dictionary method?

  • (A) update()
  • (B) get()
  • (C) append()
  • (D) popitem()

A

Admin • 825.56K Points
Coach

Q. Which of the following can be a dictionary key?

  • (A) A list
  • (B) A dictionary
  • (C) A tuple
  • (D) A set

A

Admin • 825.56K Points
Coach

Q. What does the `update()` method do?

  • (A) Removes a key
  • (B) Returns the length
  • (C) Adds key-value pairs from another dict
  • (D) Sorts the dictionary

A

Admin • 825.56K Points
Coach

Q. How do you iterate over keys and values in a dictionary?

  • (A) for k, v in dict.items():
  • (B) for k, v in dict.get():
  • (C) for k, v in dict.elements():
  • (D) for k, v in dict.keys():

A

Admin • 825.56K Points
Coach

Q. Which statement will throw a KeyError?

  • (A) dict.get('x')
  • (B) dict['x']
  • (C) 'x' in dict
  • (D) dict.keys()

A

Admin • 825.56K Points
Coach

Q. How do you copy a dictionary?

  • (A) copy = dict
  • (B) copy = dict.clone()
  • (C) copy = dict.copy()
  • (D) copy = dict.duplicate()

A

Admin • 825.56K Points
Coach

Q. Which of the following statements will correctly initialize an empty dictionary?

  • (A) my_dict = []
  • (B) my_dict = dict()
  • (C) my_dict = ()
  • (D) my_dict = set()
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