Skip to content
Question 28 of 97

Q.Which of the following built-in function/method returns a dictionary ? (A) dict() (B) keys() (C) values() (D) items()

Rajasthan RbseCBSE Class XII Board 2025MCQ· 1mImportance★★★★★
29% · 28/97 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

A dictionary is returned by the constructor that creates one from scratch or from an iterable of key-value pairs. The answer is (A) dict().

The concept: constructors versus accessor methods

Python's dictionary type offers two kinds of operations. The constructor dict() builds and returns a new dictionary object. The methods keys(), values(), and items() are called on an existing dictionary and return views of its contents, not new dictionaries.

Understanding the return type of each is essential for working with dictionaries correctly.


Examining each option

  1. dict() — the dictionary constructor

    This is Python's built-in function that creates a dictionary. Called with no arguments, it returns an empty dictionary:

    d = dict()  # returns {}
    

    Called with keyword arguments or an iterable of pairs, it constructs and returns a populated dictionary:

    dict(a=1, b=2)           # returns {'a': 1, 'b': 2}
    dict([('x', 10), ('y', 20)])  # returns {'x': 10, 'y': 20}
    

    The return type is <class 'dict'>.

  2. keys() — returns a view of keys

    This is a method called on an existing dictionary. It returns a dict_keys object, which is a view (not a dictionary):

    d = {'a': 1, 'b': 2}
    k = d.keys()  # returns dict_keys(['a', 'b'])
    type(k)       # <class 'dict_keys'>
    

    You can iterate over it or convert it to a list, but it is not a dictionary.

  3. values() — returns a view of values

    Similarly, this method returns a dict_values object:

    v = d.values()  # returns dict_values([1, 2])
    type(v)         # <class 'dict_values'>
    ``` …
    

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.