1. Home
  2. Data Science
  3. Python
  4. What will be the output of {'a': 1, 'b': 2}.values() in…

Added 4 May 2024

What will be the output of {'a': 1, 'b': 2}.values() in Python?

  1. [1, 2] Correct answer
  2. {'a': 1, 'b': 2}
  3. (1, 2)
  4. Error

Correct answer

A. [1, 2]

11 views

MCQSEXAM

Explanation

values() returns a dict_values view object, shown as dict_values([1, 2]). Of the options given, [1, 2] is the closest, since the view contains the values 1 and 2 in a list-like form; it is not a tuple or dictionary.

Doubts & discussion

Not sure why the answer is A? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Python MCQs

Practise all Python MCQs

Similar MCQs