Q.Which of the following built-in function/method returns a dictionary ? (A) dict() (B) keys() (C) values() (D) items()
🔒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 →Concept understanding — Python Dictionary Operations
A dictionary in Python is a mutable, unordered collection of key-value pairs where each unique key maps to a value, written as {key: value}. Values are accessed, added or updated by key, and methods such as keys(), values(), items(), get(), update() and pop() operate on the pairs. Iterating over a dictionary yields its keys by default, allowing traversal of all entries, and …
Concept: Return types of Python dictionary functions and constructors.
We need to identify which function/method produces a dictionary object as output.
dict() is a built-in constructor that creates and returns a new dictionary. You can call it empty (dict()), with keyword arguments (dict(a=1, b=2)), or from an iterable of pairs — in all cases it returns a dict object. …
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
-
dict()— the dictionary constructorThis 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'>. -
keys()— returns a view of keysThis is a method called on an existing dictionary. It returns a
dict_keysobject, 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.
-
values()— returns a view of valuesSimilarly, this method returns a
dict_valuesobject:v = d.values() # returns dict_values([1, 2]) type(v) # <class 'dict_values'> ``` …
- CBSE 2026Set 91/41 markMCQQ.Which of the following statements is true about dictionaries in Python ? (A) A dictionary is an example of sequence datatype. (B) A dictionary cannot have two elements with same key. (C) A dictionary cannot have two elements with same value. (D) The key and value of an element cannot be the same.
›Reveal solutionSolution
Dictionaries are mappings, not sequences; keys must be unique, but values can repeat, and a key can equal its value. Only statement (B) is correct.
The Concept: What a Dictionary Actually Is
A Python dictionary is a mapping type — it stores key-value pairs, where each key is used to look up its associated value. This is fundamentally different from a sequence (like a list, tuple, or string), which stores items in a positional order. Sequences are indexed by integers; dictionaries are indexed by their keys.
The core rules are:
- Keys must be unique — you cannot have two entries with the same key.
- Keys must be immutable (strings, numbers, tuples of immutables).
- Values have no restrictions — they can be any object, and they can repeat freely.
- There is no rule that a key and its value must be different.
Now let’s test each statement against these rules.
Step-by-Step Analysis
1. Statement (A): “A dictionary is an example of sequence datatype.”
A sequence is an ordered collection where elements are accessed by their position (index). Lists, tuples, and strings are sequences. A dictionary is unordered (in Python <3.7) or insertion-ordered (Python ≥3.7), but it is not accessed by integer index — it is accessed by key. It belongs to the mapping category, not sequence.
Therefore, (A) is false.
2. Statement (B): “A dictionary cannot have two elements with the same key.”
This is the defining rule of dictionaries. If you try to assign a value to an existing key, the old value is overwritten — you never get two entries with the same key. For example:
d = {'a': 1, 'a': 2} # This results in {'a': 2}, not two 'a' entriesThe language enforces key uniqueness. So (B) is true. …
- CBSE 2025Set 91/41 markMCQQ.Consider the statements given below and then choose the correct output from the given options:
(A) S01#S02# (B) 95#96# (C) S01,95#S02,96# (D) S01#95#S02#96#D={'S01':95, 'S02':96 } for I in D: print(I,end='#')›Reveal solutionSolution
When a
forloop iterates directly over a Python dictionary, it processes the dictionary's keys. Theprint()function withend='#'will output each key followed by a hash symbol, resulting inS01#S02#.A Python dictionary stores data as key-value pairs. Understanding how to iterate over these structures is fundamental. When you use a
forloop directly on a dictionary, Python has a specific default behavior: it iterates over the keys of the dictionary. The loop variable will sequentially take on each key.Additionally, the
print()function in Python, by default, adds a newline character (\n) after whatever it prints. However, you can modify this behavior using theendparameter. If you setend='#', then instead of a newline, a hash symbol (#) will be appended after each item printed.Let's break down the execution step-by-step.
-
Dictionary Initialization:
The code begins by defining a dictionary
D:D = {'S01':95, 'S02':96}This dictionary contains two key-value pairs:
- The key
'S01'is associated with the value95. - The key
'S02'is associated with the value96.
- The key
-
Looping through the Dictionary:
Next, a
forloop is initiated:for I in D:.As discussed, when you iterate directly over a dictionary
D, the loop variableIwill take on the keys of the dictionary, one by one. -
First Iteration:
In the first pass of the loop,
Iis assigned the first key fromD, which is'S01'.The statement inside the loop is
print(I, end='#').This command prints the current value of
I(which is'S01') and then appends the character specified byend, which is'#'.The output generated at this point is
S01#. -
Second Iteration: …
-
- CBSE 2025Set 91/41 markMCQQ.Which of the following built-in function/method returns a dictionary ? (A) dict() (B) keys() (C) values() (D) items()
›Reveal solutionSolution
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 methodskeys(),values(), anditems()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
-
dict()— the dictionary constructorThis 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'>. -
keys()— returns a view of keysThis is a method called on an existing dictionary. It returns a
dict_keysobject, 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.
-
values()— returns a view of valuesSimilarly, this method returns a
dict_valuesobject:v = d.values() # returns dict_values([1, 2]) type(v) # <class 'dict_values'> ``` …
-
- CBSE 2024Set 91/41 markMCQQ.Identify the invalid Python statement from the following: (A) d = dict() (B) e = {} (C) f = [] (D) g = dict{}
›Reveal solutionSolution
Python provides specific syntax for creating empty dictionaries (
dict()or{}) and lists ([]orlist());dict{}is not a valid way to create a dictionary and will result in a syntax error. The invalid statement is (D).Concept and Intuition
In Python, data structures like lists and dictionaries are fundamental for organizing data. Python offers multiple ways to create these structures, primarily through two methods:
- Constructor functions: Using the type name followed by parentheses, like
list()ordict(). These are functions that return an empty instance of that type. - Literal syntax: Using special symbols that directly represent the structure, like
[]for an empty list or{}for an empty dictionary. This is often more concise and idiomatic Python.
Both methods achieve the same result for creating empty structures, but they are distinct syntactical forms. The key is to use the correct syntax for each method.
Step-by-step Analysis
-
Statement (A):
d = dict()This statement uses the
dict()constructor function to create an empty dictionary. Thedict()function, when called without arguments, returns a new, empty dictionary. This is a perfectly valid and common way to initialize an empty dictionary in Python.After this statement,
dwill be an empty dictionary, equivalent to{}. -
Statement (B):
e = {}This statement uses the literal syntax for creating an empty dictionary. Curly braces
{}are the standard way to define dictionary literals in Python. When empty, they represent an empty dictionary. This is also a perfectly valid and very common, often preferred, way to initialize an empty dictionary.Watch outWhile
{}creates an empty dictionary, if you need an empty set, you must useset(). An empty set cannot be created with{}because{}is reserved for empty dictionaries. For example,type({})is<class 'dict'>, whiletype(set())is<class 'set'>. -
Statement (C):
f = []This statement uses the literal syntax for creating an empty list. Square brackets
[]are the standard way to define list literals in Python. When empty, they represent an empty list. This is a valid and widely used way to initialize an empty list.Alternatively, one could use
f = list(), which also creates an empty list using thelist()constructor. -
Statement (D):
g = dict{}…
- Constructor functions: Using the type name followed by parentheses, like
- CBSE 2023Set 91/11 markMCQQ.Which of the following statement(s) would give an error after executing the following code? stud={"Murugan":100, "Mithu":95} # Statement 1 print(stud[95]) # Statement 2 Stud["Murugan"]=99 # Statement 3 print(Stud.pop()) # Statement 4 print(Stud) # Statement 5(a) Statement 2(b) Statement 3(c) Statement 4(d) Statement 2 and 4
›Reveal solutionSolution
A Python dictionary is accessed by its keys, and its
pop()method needs the key to remove.print(stud[95])fails because95is a value, not a key (KeyError), andprint(Stud.pop())fails becausepop()is called with no key (TypeError). The two error statements are 2 and 4, so the answer is (d).Understanding the code
stud = {"Murugan": 100, "Mithu": 95} # Statement 1 print(stud[95]) # Statement 2 Stud["Murugan"] = 99 # Statement 3 print(Stud.pop()) # Statement 4 print(Stud) # Statement 5A dictionary stores key : value pairs. Here the keys are the strings
"Murugan"and"Mithu", and the values are100and95.Why Statement 2 errors
stud[95]tries to use95as a key. But95is a value in the dictionary, not a key — you cannot look a dictionary up by its value using square brackets. Python therefore raises:KeyError: 95Why Statement 4 errors
For a list,
pop()can be called with no argument (it removes the last item). For a dictionary,pop()must be told which key to remove, so it needs an argument. Calling it with none raises:TypeError: pop expected at least 1 argument, got 0So Statement 4 also errors. …
- CBSE 2023Set 91/41 markMCQQ.Given the following dictionary Day={1:"Monday", 2: "Tuesday", 3: "Wednesday"} Which statement will return "Tuesday".(a) Day.pop()(b) Day.pop(2)(c) Day.pop(1)(d) Day.pop("Tuesday")
›Reveal solutionSolution
The
pop()method for dictionaries removes an item by its key and returns the associated value. To return "Tuesday", we need topop()the key2. The correct option is (b).Concept and Intuition
In Python, dictionaries store data as key-value pairs. The
pop()method is used to remove a specific key-value pair from a dictionary. Crucially, it returns the value associated with the key that was removed. This is different from methods likedel dict[key], which removes the item but doesn't return anything.The
pop()method requires at least one argument: thekeyof the item you want to remove.- If the
keyexists in the dictionary,pop(key)removes the key-value pair and returns thevalue. - If the
keydoes not exist,pop(key)raises aKeyError. - You can also provide a second optional argument,
default_value, likepop(key, default_value). If thekeyis not found, it returnsdefault_valueinstead of raising aKeyError.
Watch outFor dictionaries,
pop()always requires a key as an argument (or a key and a default value). CallingDay.pop()without any arguments will result in aTypeError, unlikelist.pop()which removes and returns the last item of a list. This is a common point of confusion.We are looking for the statement that will return the string "Tuesday". This means we need to identify which option correctly uses
pop()to target the key associated with "Tuesday".Step-by-step Solution
Let's analyze each option given the dictionary
Day = {1: "Monday", 2: "Tuesday", 3: "Wednesday"}.-
Analyze option (a)
Day.pop()- This statement attempts to call
pop()without any arguments. - As explained in the concept, the dictionary
pop()method requires a key. - Executing
Day.pop()will raise aTypeError. - Therefore, this statement will not return "Tuesday".
- This statement attempts to call
-
Analyze option (b)
Day.pop(2)- This statement calls
pop()with the argument2. - In our dictionary
Day, the key2exists, and its corresponding value is "Tuesday". Day.pop(2)will remove the key-value pair(2: "Tuesday")from the dictionary and return the value "Tuesday". …
- This statement calls
- If the
- CBSE 2020Set 91/D1 markQ.Write a Python statement to declare a Dictionary named ClassRoll with Keys as 1, 2, 3 and corresponding values as 'Reena', 'Rakesh', 'Zareen' respectively.
›Reveal solutionSolution
A dictionary in Python is declared using curly braces with key-value pairs separated by colons;
ClassRoll = {1: 'Reena', 2: 'Rakesh', 3: 'Zareen'}creates the required structure.Dictionaries are one of Python's most powerful built-in data structures, designed to store data as key-value pairs rather than in a simple sequence. Think of them as a real-world dictionary where you look up a word (the key) to find its meaning (the value), or in this case, a roll number to find a student's name.
The syntax is straightforward. You enclose the entire collection in curly braces
{}, and inside, each key is linked to its value with a colon:. Multiple pairs are separated by commas. The keys here are integers (1, 2, 3) representing roll numbers, and the values are strings ('Reena', 'Rakesh', 'Zareen') representing student names.Here's the complete statement:
ClassRoll = {1: 'Reena', 2: 'Rakesh', 3: 'Zareen'} ``` …
🎓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.