Python Dictionary MCQs with answers Page - 5

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 output of: `d = {'x': 100, 'y': 200}; d['z'] = d.get('z', 300)`?

  • (A) {'x': 100, 'y': 200}
  • (B) {'x': 100, 'y': 200, 'z': 300}
  • (C) Error
  • (D) {'z': 300}

A

Admin • 825.56K Points
Coach

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

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

A

Admin • 825.56K Points
Coach

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

  • (A) Reversed dictionary
  • (B) Reversed key-value pairs
  • (C) Reversed keys iterator
  • (D) Error

A

Admin • 825.56K Points
Coach

Q. Which is the most memory-efficient way to create a dictionary?

  • (A) dict = {}
  • (B) dict = dict()
  • (C) dict = dict.fromkeys([])
  • (D) dict = collections.defaultdict()

A

Admin • 825.56K Points
Coach

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

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

A

Admin • 825.56K Points
Coach

Q. What does `any({'': 1, 'b': 0})` return?

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

A

Admin • 825.56K Points
Coach

Q. What is the result of `{1: 'a', 1.0: 'b'}`?

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

A

Admin • 825.56K Points
Coach

Q. Which method creates a shallow copy of a dictionary?

  • (A) clone()
  • (B) copy()
  • (C) duplicate()
  • (D) replicate()

A

Admin • 825.56K Points
Coach

Q. What does the expression `'key' not in my_dict` evaluate?

  • (A) True if 'key' exists
  • (B) False if 'key' exists
  • (C) True if 'key' does not exist
  • (D) Syntax Error

A

Admin • 825.56K Points
Coach

Q. Which of the following is **not** valid syntax?

  • (A) {'a': 1, 'b': 2}
  • (B) dict(a=1, b=2)
  • (C) {[1, 2]: 'value'}
  • (D) dict([(1, 'a'), (2, 'b')])
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