Dictionary In Python — Part 1 MCQs with Explanations
Practice high-yield Programming & Software Development MCQs on Dictionary In Python — Part 1 with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.
Questions
40
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
48 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
40
Verified Practice Questions
Interactive test mode with detailed academic worked solutions
Live Progress|0/40 answered
✓0 correct
✗0 wrong
0% score
🎉 Set complete! All 40 questions answered.
Question 1 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the popitem() method for dictionaries?
Correct Answer: Option B — Removes and returns a random key-value pair from the dictionary
Detailed Academic Explanation:
Imagine a dictionary as a box filled with labeled items. Each label is a key , and the item is its value . The popitem() method acts like taking out one item from that box. But which item does it take? It's important to understand that unlike lists, dictionaries don't have a strict "first" or "last" item. Option A says it removes the last item. This is not entirely accurate because dictionaries aren't ordered like lists. Option B says it's random. This is also incorrect. While the order might seem random, it's actually determined by how Python stores the data internally; it's not truly random selection. Option C suggests it removes the first. Again, dictionaries don't have a defined "first" element. Option B is the closest, but not entirely precise. It removes and returns an arbitrary key-value pair. In Python versions before 3.7, the order might appear random. In Python 3.7+, the order is insertion order, but popitem() still removes an arbitrary key-value pair (it's still efficient for removing and retrieving any single element). Option D is incorrect; there's a different method ( pop() ) for removing a specific key-value pair. popitem() always removes any key-value pair, not one you specify. Therefore, the most accurate description among the choices is that popitem() removes and returns an arbitrary key-value pair from the dictionary. The exact order is implementation-defined but usually reflects insertion order in newer versions of Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 2 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following code: my_dict = {'a': 1, 'b': 2} my_dict.popitem() print(my_dict)
Correct Answer: Option C — {'b': 2}
Detailed Academic Explanation:
Code Analysis: my_dict = {'a': 1, 'b': 2} 1. popitem() Method: The popitem() method removes and returns the last inserted key-value pair. In this case, the last inserted pair is 'b': 2 . 2. Updated Dictionary: After removing 'b': 2 , the dictionary will contain only 'a': 1 . print(my_dict) Output: The dictionary now contains {'a': 1} . Incorrect Options: A) {'a': 1, 'b': 2}: This would be the original dictionary, but popitem() modifies it. B) {}: This would be true if both key-value pairs were removed, but only one is removed. D) {1: 'a', 2: 'b'}: This is incorrect as keys and values are not swapped. Thus, the correct answer is Option C: {'a': 1} .
💡Key Conceptual Anchor:Dictionary In Python
Question 3 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following data types in Python is used to store key-value pairs?
Correct Answer: Option A — Dictionary
Detailed Academic Explanation:
Dictionary is the correct answer to “Which of the following data types in Python is used to store key-value pairs”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 4 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What method is used to check if a key exists in a dictionary, and if not, add it with a default value?
Correct Answer: Option A — setdefault()
Detailed Academic Explanation:
setdefault() is the correct answer to “What method is used to check if a key exists in a dictionary, and if not, add it with a default value”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 5 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the len() function do when applied to a dictionary?
Correct Answer: Option A — Returns the number of key-value pairs in the dictionary
Detailed Academic Explanation:
Returns the number of key-value pairs in the dictionary is the correct answer to “What does the len() function do when applied to a dictionary”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 6 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Python, how can you get a list of all key-value pairs in a dictionary?
Correct Answer: Option A — items()
Detailed Academic Explanation:
items() is the correct answer to “In Python, how can you get a list of all key-value pairs in a dictionary”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 7 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the dict() constructor in Python?
Correct Answer: Option A — Creates a new dictionary
Detailed Academic Explanation:
Creates a new dictionary is the correct answer to “What is the purpose of the dict() constructor in Python”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 8 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method is used to remove a key-value pair from a dictionary?
Correct Answer: Option A — pop()
Detailed Academic Explanation:
pop() is the correct answer to “Which method is used to remove a key-value pair from a dictionary”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 9 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Python, how can you check if a key exists in a dictionary?
Correct Answer: Option A — in keyword
Detailed Academic Explanation:
in keyword is the correct answer to “In Python, how can you check if a key exists in a dictionary”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 10 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What method is used to update the values of a dictionary with the values from another dictionary?
Correct Answer: Option A — update()
Detailed Academic Explanation:
update() is the correct answer to “What method is used to update the values of a dictionary with the values from another dictionary”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 11 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the keys() method for dictionaries?
Correct Answer: Option A — Returns a list of all keys in the dictionary
Detailed Academic Explanation:
Returns a list of all keys in the dictionary is the correct answer to “What is the purpose of the keys() method for dictionaries”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 12 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method is used to get a list of all values in a dictionary?
Correct Answer: Option A — values()
Detailed Academic Explanation:
values() is the correct answer to “Which method is used to get a list of all values in a dictionary”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 13 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Python, how can you remove all key-value pairs from a dictionary?
Correct Answer: Option A — clear()
Detailed Academic Explanation:
clear() is the correct answer to “In Python, how can you remove all key-value pairs from a dictionary”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 14 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the items() method for dictionaries?
Correct Answer: Option A — Returns a list of key-value pairs in the dictionary
Detailed Academic Explanation:
Returns a list of key-value pairs in the dictionary is the correct answer to “What is the purpose of the items() method for dictionaries”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 15 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method is used to create a shallow copy of a dictionary?
Correct Answer: Option A — copy()
Detailed Academic Explanation:
copy() is the correct answer to “Which method is used to create a shallow copy of a dictionary”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 16 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the clear() method for dictionaries?
Correct Answer: Option A — Removes all key-value pairs from the dictionary
Detailed Academic Explanation:
Removes all key-value pairs from the dictionary is the correct answer to “What is the purpose of the clear() method for dictionaries”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 17 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the fromkeys() method for dictionaries?
Correct Answer: Option A — Creates a new dictionary with specified keys and a default value
Detailed Academic Explanation:
Creates a new dictionary with specified keys and a default value is the correct answer to “What is the purpose of the fromkeys() method for dictionaries”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 18 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Python, how can you get a list of all keys in a dictionary?
Correct Answer: Option A — keys()
Detailed Academic Explanation:
keys() is the correct answer to “In Python, how can you get a list of all keys in a dictionary”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 19 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following code: my_dict = {'a': 1, 'b': 2} print(my_dict['a'])
Correct Answer: Option A — 1
Detailed Academic Explanation:
1 is the correct answer to “What is the output of the following code: my_dict = {'a': 1, 'b': 2} print(my_dict['a'])”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 20 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How can you add a new key-value pair to a dictionary in Python?
Correct Answer: Option A — my_dict['new_key'] = new_value
Detailed Academic Explanation:
my_dict['new_key'] = new_value is the correct answer to “How can you add a new key-value pair to a dictionary in Python”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 21 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Python, how can you create an empty dictionary?
Correct Answer: Option A — dict()
Detailed Academic Explanation:
dict() is the correct answer to “In Python, how can you create an empty dictionary”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 22 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the values() method for dictionaries?
Correct Answer: Option A — Returns a list of all values in the dictionary
Detailed Academic Explanation:
Returns a list of all values in the dictionary is the correct answer to “What is the purpose of the values() method for dictionaries”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 23 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following code: my_dict = {'a': 1, 'b': 2} my_dict['c'] = 3 print(my_dict)
{'a': 1, 'b': 2, 'c': 3} is the correct answer to “What will be the output of the following code: my_dict = {'a': 1, 'b': 2} my_dict['c'] = 3 print(my_dict)”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 24 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following code: my_dict = {'a': 1, 'b': 2, 'c': 3} my_dict.pop('b') print(my_dict)
Correct Answer: Option B — {'a': 1, 'c': 3}
Detailed Academic Explanation:
{'a': 1, 'c': 3} is the correct answer to “What is the output of the following code: my_dict = {'a': 1, 'b': 2, 'c': 3} my_dict.pop('b') print(my_dict)”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 25 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following code: my_dict = {'a': 1, 'b': 2, 'c': 3} print(my_dict.get('d', 0))
Correct Answer: Option A — 0
Detailed Academic Explanation:
0 is the correct answer to “What is the output of the following code: my_dict = {'a': 1, 'b': 2, 'c': 3} print(my_dict.get('d', 0))”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 26 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following code: my_dict = {'a': 1, 'b': 2, 'c': 3} my_dict.values() print(my_dict)
{'a': 1, 'b': 2, 'c': 3} is the correct answer to “What is the output of the following code: my_dict = {'a': 1, 'b': 2, 'c': 3} my_dict.values() print(my_dict)”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 27 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following code: my_dict = {'a': 1, 'b': 2, 'c': 3} my_dict.items() print(my_dict)
{'a': 1, 'b': 2, 'c': 3} is the correct answer to “What will be the output of the following code: my_dict = {'a': 1, 'b': 2, 'c': 3} my_dict.items() print(my_dict)”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 28 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following code: my_dict = {'a': 1, 'b': 2} del my_dict['b'] print(my_dict)
Correct Answer: Option B — {'a': 1}
Detailed Academic Explanation:
{'a': 1} is the correct answer to “What is the output of the following code: my_dict = {'a': 1, 'b': 2} del my_dict['b'] print(my_dict)”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 29 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following code: my_dict = {'a': 1, 'b': 2} new_dict = my_dict.copy() print(new_dict)
Correct Answer: Option A — {'a': 1, 'b': 2}
Detailed Academic Explanation:
{'a': 1, 'b': 2} is the correct answer to “What is the output of the following code: my_dict = {'a': 1, 'b': 2} new_dict = my_dict.copy() print(new_dict)”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 30 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following code: keys = ['a', 'b', 'c'] values = 0 my_dict = dict.fromkeys(keys, values) print(my_dict)
{'a': 0, 'b': 0, 'c': 0} is the correct answer to “What will be the output of the following code: keys = ['a', 'b', 'c'] values = 0 my_dict = dict.fromkeys(keys, values) print(my_dict)”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 31 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? >>> import collections >>> a=collections.OrderedDict((str(x),x) for x in range(3)) >>> a
OrderedDict([('0', 0), ('1', 1), ('2', 2)]) is the correct answer to “What will be the output of the following Python code? >>> import collections >>> a=collections.OrderedDict((str(x),x) for x in range(3)) >>> a”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 32 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? >>> a={} >>> a.fromkeys([1,2,3],"check")
Correct Answer: Option B — {1:"check",2:"check",3:"check"}
Detailed Academic Explanation:
{1:"check",2:"check",3:"check"} is the correct answer to “What will be the output of the following Python code? >>> a={} >>> a.fromkeys([1,2,3],"check")”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 33 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code snippet? d1 = {"john":40, "peter":45} d2 = {"john":466, "peter":45} d1 == d2
Correct Answer: Option B — False
Detailed Academic Explanation:
False is the correct answer to “What will be the output of the following Python code snippet? d1 = {"john":40, "peter":45} d2 = {"john":466, "peter":45} d1 == d2”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 34 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code snippet? d = {"john":40, "peter":45} print(list(d.keys()))
Correct Answer: Option A — ["john", "peter"]
Detailed Academic Explanation:
["john", "peter"] is the correct answer to “What will be the output of the following Python code snippet? d = {"john":40, "peter":45} print(list(d.keys()))”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 35 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code snippet? test = {1:'A', 2:'B', 3:'C'} test = {} print(len(test))
Correct Answer: Option A — 0
Detailed Academic Explanation:
0 is the correct answer to “What will be the output of the following Python code snippet? test = {1:'A', 2:'B', 3:'C'} test = {} print(len(test))”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 36 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following statements create a dictionary?
Correct Answer: Option D — All of the mentioned
Detailed Academic Explanation:
All of the mentioned is the correct answer to “Which of the following statements create a dictionary”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 37 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code snippet? a={1:"A",2:"B",3:"C"} for i,j in a.items(): print(i,j,end=" ")
Correct Answer: Option A — 1 A 2 B 3 C
Detailed Academic Explanation:
1 A 2 B 3 C is the correct answer to “What will be the output of the following Python code snippet? a={1:"A",2:"B",3:"C"} for i,j in a.items(): print(i,j,end=" ")”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 38 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code snippet? test = {1:'A', 2:'B', 3:'C'} del test[1] test[1] = 'D' del test[2] print(len(test))
Correct Answer: Option B — 2
Detailed Academic Explanation:
2 is the correct answer to “What will be the output of the following Python code snippet? test = {1:'A', 2:'B', 3:'C'} del test[1] test[1] = 'D' del test[2] print(len(test))”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 39 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? >>> a={1:"A",2:"B",3:"C"} >>> a.items()
dict_items([(1, 'A'), (2, 'B'), (3, 'C')]) is the correct answer to “What will be the output of the following Python code? >>> a={1:"A",2:"B",3:"C"} >>> a.items()”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 40 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the statements about dictionary values if false?
Correct Answer: Option C — Values of a dictionary must be unique
Detailed Academic Explanation:
Values of a dictionary must be unique is the correct answer to “Which of the statements about dictionary values if false”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
✓Link copied to clipboard
Continue Your Practice
Advance Html — Part 1
Master the next curriculum module with 40 exam-standard MCQs.
💡Examiner's Advisory for Programming & Software Development
In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.