Skip to main content

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
Question 1 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code? >>> a=dict() >>> a[1]

Question 2 of 40
★ 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)

Question 3 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code? a={1:5,2:3,3:4} print(a.pop(4,9))

Question 4 of 40
★ 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

Question 5 of 40
★ 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)

Question 6 of 40
★ FPSC ★ PPSC

Suppose d = {"john":40, "peter":45}. To obtain the number of entries in dictionary which command do we use?

Question 7 of 40
★ FPSC ★ PPSC

The following Python code is invalid. class demo(dict): def __test__(self,key): return [] a = demo() a['test'] = 7 print(a)

Question 8 of 40
★ 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])

Question 9 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code? >>> import collections >>> a=dict() >>> a=collections.defaultdict(str) >>> a['A']

Question 10 of 40
★ 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)

Question 11 of 40
★ 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=" ")

Question 12 of 40
★ FPSC ★ PPSC

Which of these about a dictionary is false?

Question 13 of 40
★ 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)

Question 14 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code? a={1:5,2:3,3:4} a.pop(3) print(a)

Question 15 of 40
★ 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)

Question 16 of 40
★ 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

Question 17 of 40
★ FPSC ★ PPSC

If b is a dictionary, what does any(b) do?

Question 18 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code snippet? >>> a={1:"A",2:"B",3:"C"} >>> del a

Question 19 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code? a={1:"A",2:"B",3:"C"} a.clear() print(a)

Question 20 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code? >>> a={i: i*i for i in range(6)} >>> a

Question 21 of 40
★ 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)

Question 22 of 40
★ FPSC ★ PPSC

Which of the following is not a declaration of the dictionary?

Question 23 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code snippet? d = {"john":40, "peter":45} "john" in d

Question 24 of 40
★ 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))

Question 25 of 40
★ FPSC ★ PPSC

If a is a dictionary with some key-value pairs, what does a.popitem() do?

Question 26 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code snippet? d = {"john":40, "peter":45} d["john"]

Question 27 of 40
★ 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))

Question 28 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code snippet? a={1:"A",2:"B",3:"C"} print(a.setdefault(3))

Question 29 of 40
★ FPSC ★ PPSC

Suppose d = {"john":40, "peter":45}, to delete the entry for "john" what command do we use?

Question 30 of 40
★ 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)

Question 31 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code? >>> import collections >>> a=dict() >>> a=collections.defaultdict(int) >>> a[1]

Question 32 of 40
★ FPSC ★ PPSC

Suppose d = {"john":40, "peter":45}, what happens when we try to retrieve a value using the expression d["susan"]?

Question 33 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code snippet? a={} a['a']=1 a['b']=[2,3,4] print(a)

Question 34 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code? >>> a={'B':5,'A':9,'C':7} >>> sorted(a)

Question 35 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code? >>> import collections >>> b=dict() >>> b=collections.defaultdict(lambda: 7) >>> b[4]

Question 36 of 40
★ 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

Question 37 of 40
★ FPSC ★ PPSC

Which of the following isn't true about dictionary keys?

Question 38 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code? >>> a={i: 'A' + str(i) for i in range(5)} >>> a

Question 39 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code? >>> b={} >>> all(b)

Question 40 of 40
★ 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))

✓ Link copied to clipboard
Continue Your Practice

Advance Html — Part 1

Master the next curriculum module with 40 exam-standard MCQs.

Next Practice Set →

💡 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.

More Modules in Programming & Software Development

View All →
📚

Study Guides

Topic summaries and syllabus breakdown

Explore Guides →
🎯

Complete Library

Search through 78,000+ verified MCQs

Browse Library →
📱

Mobile App

Offline mock tests and instant bookmarks

Get Mobile App →