Dictionary In Python — Part 2 MCQs with Explanations
Practice high-yield Programming & Software Development MCQs on Dictionary In Python — Part 2 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 will be the output of the following Python code? >>> a=dict() >>> a[1]
Correct Answer: Option A — An exception is thrown since the dictionary is empty
Detailed Academic Explanation:
An exception is thrown since the dictionary is empty is the correct answer to “What will be the output of the following Python code? >>> a=dict() >>> a[1]”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 2 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code snippet? a={1:"A",2:"B",3:"C"} a.setdefault(4,"D") print(a)
{1: 'A', 2: 'B', 3: 'C', 4: 'D'} is the correct answer to “What will be the output of the following Python code snippet? a={1:"A",2:"B",3:"C"} a.setdefault(4,"D") print(a)”. This question is standard in competitive examination syllabi for Dictionary In Python.
💡Key Conceptual Anchor:Dictionary In Python
Question 3 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? a={1:5,2:3,3:4} print(a.pop(4,9))
Correct Answer: Option A — 9
Detailed Academic Explanation:
9 is the correct answer to “What will be the output of the following Python code? a={1:5,2:3,3:4} print(a.pop(4,9))”. 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 will be the output of the following Python code snippet? >>> import collections >>> a=collections.Counter([3,3,4,5]) >>> b=collections.Counter([3,4,4,5,5,5]) >>> a&b
Counter({3: 1, 4: 1, 5: 1}) is the correct answer to “What will be the output of the following Python code snippet? >>> import collections >>> a=collections.Counter([3,3,4,5]) >>> b=collections.Counter([3,4,4,5,5,5]) >>> a&b”. 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 will be the output of the following Python code snippet? >>>import collections >>> b=collections.Counter([2,2,3,4,4,4]) >>> b.most_common(1)
Correct Answer: Option D — [(4, 3)]
Detailed Academic Explanation:
[(4, 3)] is the correct answer to “What will be the output of the following Python code snippet? >>>import collections >>> b=collections.Counter([2,2,3,4,4,4]) >>> b.most_common(1)”. 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
Suppose d = {"john":40, "peter":45}. To obtain the number of entries in dictionary which command do we use?
Correct Answer: Option B — len(d)
Detailed Academic Explanation:
len(d) is the correct answer to “Suppose d = {"john":40, "peter":45}. To obtain the number of entries in dictionary which command do we use”. 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
The following Python code is invalid. class demo(dict): def __test__(self,key): return [] a = demo() a['test'] = 7 print(a)
Correct Answer: Option B — False
Detailed Academic Explanation:
False is the correct answer to “The following Python code is invalid. class demo(dict): def __test__(self,key): return [] a = demo() a['test'] = 7 print(a)”. 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
What will be the output of the following Python code? a={} a[2]=1 a[1]=[2,3,4] print(a[1][1])
Correct Answer: Option B — 3
Detailed Academic Explanation:
3 is the correct answer to “What will be the output of the following Python code? a={} a[2]=1 a[1]=[2,3,4] print(a[1][1])”. 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
What will be the output of the following Python code? >>> import collections >>> a=dict() >>> a=collections.defaultdict(str) >>> a['A']
Correct Answer: Option B — ' '
Detailed Academic Explanation:
' ' is the correct answer to “What will be the output of the following Python code? >>> import collections >>> a=dict() >>> a=collections.defaultdict(str) >>> a['A']”. 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 will be the output of the following Python code? count={} count[(1,2,4)] = 5 count[(4,2,1)] = 7 count[(1,2)] = 6 count[(4,2,1)] = 2 tot = 0 for i in count: tot=tot+count[i] print(len(count)+tot)
Correct Answer: Option C — 16
Detailed Academic Explanation:
16 is the correct answer to “What will be the output of the following Python code? count={} count[(1,2,4)] = 5 count[(4,2,1)] = 7 count[(1,2)] = 6 count[(4,2,1)] = 2 tot = 0 for i in count: tot=tot+count[i] print(len(count)+tot)”. 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 will be the output of the following Python code? a={1:"A",2:"B",3:"C"} for i in a: print(i,end=" ")
Correct Answer: Option A — 1 2 3
Detailed Academic Explanation:
1 2 3 is the correct answer to “What will be the output of the following Python code? a={1:"A",2:"B",3:"C"} for i in a: print(i,end=" ")”. 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 of these about a dictionary is false?
Correct Answer: Option B — The keys of a dictionary can be accessed using values
Detailed Academic Explanation:
The keys of a dictionary can be accessed using values is the correct answer to “Which of these about a dictionary is false”. 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
What will be the output of the following Python code? a={1:"A",2:"B",3:"C"} b=a.copy() b[2]="D" print(a)
{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"} b=a.copy() b[2]="D" print(a)”. 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 will be the output of the following Python code? a={1:5,2:3,3:4} a.pop(3) print(a)
Correct Answer: Option B — {1: 5, 2: 3}
Detailed Academic Explanation:
{1: 5, 2: 3} is the correct answer to “What will be the output of the following Python code? a={1:5,2:3,3:4} a.pop(3) print(a)”. 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
What will be the output of the following Python code? a={1:"A",2:"B",3:"C"} b={4:"D",5:"E"} a.update(b) print(a)
{1: 'A', 2: 'B', 3: 'C', 4: 'D', 5: 'E'} is the correct answer to “What will be the output of the following Python code? a={1:"A",2:"B",3:"C"} b={4:"D",5:"E"} a.update(b) print(a)”. 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 will be the output of the following Python code snippet? >>>import collections >>> a=collections.Counter([1,1,2,3,3,4,4,4]) >>> a
Counter({4: 3, 1: 2, 3: 2, 2: 1}) is the correct answer to “What will be the output of the following Python code snippet? >>>import collections >>> a=collections.Counter([1,1,2,3,3,4,4,4]) >>> a”. 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
If b is a dictionary, what does any(b) do?
Correct Answer: Option A — Returns True if any key of the dictionary is true
Detailed Academic Explanation:
Returns True if any key of the dictionary is true is the correct answer to “If b is a dictionary, what does any(b) do”. 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
What will be the output of the following Python code snippet? >>> a={1:"A",2:"B",3:"C"} >>> del a
Correct Answer: Option C — del deletes the entire dictionary
Detailed Academic Explanation:
del deletes the entire dictionary is the correct answer to “What will be the output of the following Python code snippet? >>> a={1:"A",2:"B",3:"C"} >>> del a”. 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 will be the output of the following Python code? a={1:"A",2:"B",3:"C"} a.clear() print(a)
Correct Answer: Option D — { }
Detailed Academic Explanation:
{ } is the correct answer to “What will be the output of the following Python code? a={1:"A",2:"B",3:"C"} a.clear() print(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
What will be the output of the following Python code? >>> a={i: i*i for i in range(6)} >>> a
{0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25} is the correct answer to “What will be the output of the following Python code? >>> a={i: i*i for i in range(6)} >>> a”. 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
What will be the output of the following Python code snippet? a = {} a[1] = 1 a['1'] = 2 a[1.0]=4 count = 0 for i in a: count += a[i] print(count)
Correct Answer: Option C — 6
Detailed Academic Explanation:
6 is the correct answer to “What will be the output of the following Python code snippet? a = {} a[1] = 1 a['1'] = 2 a[1.0]=4 count = 0 for i in a: count += a[i] print(count)”. 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
Which of the following is not a declaration of the dictionary?
Correct Answer: Option C — {1,"A",2"B"}
Detailed Academic Explanation:
{1,"A",2"B"} is the correct answer to “Which of the following is not a declaration of the dictionary”. 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 Python code snippet? d = {"john":40, "peter":45} "john" in d
Correct Answer: Option A — True
Detailed Academic Explanation:
True is the correct answer to “What will be the output of the following Python code snippet? d = {"john":40, "peter":45} "john" in d”. 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 will be the output of the following Python code snippet? total={} def insert(items): if items in total: total[items] += 1 else: total[items] = 1 insert('Apple') insert('Ball') insert('Apple') print (len(total))
Correct Answer: Option C — 2
Detailed Academic Explanation:
2 is the correct answer to “What will be the output of the following Python code snippet? total={} def insert(items): if items in total: total[items] += 1 else: total[items] = 1 insert('Apple') insert('Ball') insert('Apple') print (len(total))”. 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
If a is a dictionary with some key-value pairs, what does a.popitem() do?
Correct Answer: Option A — Removes an arbitrary element
Detailed Academic Explanation:
Removes an arbitrary element is the correct answer to “If a is a dictionary with some key-value pairs, what does a.popitem() do”. 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 will be the output of the following Python code snippet? d = {"john":40, "peter":45} d["john"]
Correct Answer: Option A — 40
Detailed Academic Explanation:
40 is the correct answer to “What will be the output of the following Python code snippet? d = {"john":40, "peter":45} d["john"]”. 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 Python code snippet? a={1:"A",2:"B",3:"C"} print(a.get(5,4))
Correct Answer: Option D — 4
Detailed Academic Explanation:
4 is the correct answer to “What will be the output of the following Python code snippet? a={1:"A",2:"B",3:"C"} print(a.get(5,4))”. 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 will be the output of the following Python code snippet? a={1:"A",2:"B",3:"C"} print(a.setdefault(3))
Correct Answer: Option B — C
Detailed Academic Explanation:
C is the correct answer to “What will be the output of the following Python code snippet? a={1:"A",2:"B",3:"C"} print(a.setdefault(3))”. 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
Suppose d = {"john":40, "peter":45}, to delete the entry for "john" what command do we use?
Correct Answer: Option C — del d["john"]
Detailed Academic Explanation:
del d["john"] is the correct answer to “Suppose d = {"john":40, "peter":45}, to delete the entry for "john" what command do we use”. 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 Python code snippet? a = {} a[1] = 1 a['1'] = 2 a[1]=a[1]+1 count = 0 for i in a: count += a[i] print(count)
Correct Answer: Option C — 4
Detailed Academic Explanation:
4 is the correct answer to “What will be the output of the following Python code snippet? a = {} a[1] = 1 a['1'] = 2 a[1]=a[1]+1 count = 0 for i in a: count += a[i] print(count)”. 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=dict() >>> a=collections.defaultdict(int) >>> a[1]
Correct Answer: Option B — 0
Detailed Academic Explanation:
0 is the correct answer to “What will be the output of the following Python code? >>> import collections >>> a=dict() >>> a=collections.defaultdict(int) >>> a[1]”. 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
Suppose d = {"john":40, "peter":45}, what happens when we try to retrieve a value using the expression d["susan"]?
Correct Answer: Option C — Since "susan" is not a key in the set, Python raises a KeyError exception
Detailed Academic Explanation:
Since "susan" is not a key in the set, Python raises a KeyError exception is the correct answer to “Suppose d = {"john":40, "peter":45}, what happens when we try to retrieve a value using the expression d["susan"]”. 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? a={} a['a']=1 a['b']=[2,3,4] print(a)
{'b': [2, 3, 4], 'a': 1} is the correct answer to “What will be the output of the following Python code snippet? a={} a['a']=1 a['b']=[2,3,4] print(a)”. 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? >>> a={'B':5,'A':9,'C':7} >>> sorted(a)
Correct Answer: Option A — ['A','B','C']
Detailed Academic Explanation:
['A','B','C'] is the correct answer to “What will be the output of the following Python code? >>> a={'B':5,'A':9,'C':7} >>> sorted(a)”. 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? >>> import collections >>> b=dict() >>> b=collections.defaultdict(lambda: 7) >>> b[4]
Correct Answer: Option D — 7
Detailed Academic Explanation:
7 is the correct answer to “What will be the output of the following Python code? >>> import collections >>> b=dict() >>> b=collections.defaultdict(lambda: 7) >>> b[4]”. 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
What will be the output of the following Python code? >>> a={"a":1,"b":2,"c":3} >>> b=dict(zip(a.values(),a.keys())) >>> b
{1: 'a', 2: 'b', 3: 'c'} is the correct answer to “What will be the output of the following Python code? >>> a={"a":1,"b":2,"c":3} >>> b=dict(zip(a.values(),a.keys())) >>> b”. 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
Which of the following isn't true about dictionary keys?
Correct Answer: Option C — Keys must be integers
Detailed Academic Explanation:
Keys must be integers is the correct answer to “Which of the following isn't true about dictionary keys”. 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? >>> a={i: 'A' + str(i) for i in range(5)} >>> a
{0: 'A0', 1: 'A1', 2: 'A2', 3: 'A3', 4: 'A4'} is the correct answer to “What will be the output of the following Python code? >>> a={i: 'A' + str(i) for i in range(5)} >>> a”. 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? >>> b={} >>> all(b)
Correct Answer: Option C — True
Detailed Academic Explanation:
True is the correct answer to “What will be the output of the following Python code? >>> b={} >>> all(b)”. 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
What will be the output of the following Python code snippet? a={1:"A",2:"B",3:"C"} print(a.get(1,4))
Correct Answer: Option B — A
Detailed Academic Explanation:
A is the correct answer to “What will be the output of the following Python code snippet? a={1:"A",2:"B",3:"C"} print(a.get(1,4))”. 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.