Practice high-yield Programming & Software Development MCQs on Sets 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
The following Python code results in an error. s={2, 3, 4, [5, 6]}
Correct Answer: Option A — True
Detailed Academic Explanation:
True is the correct answer to “The following Python code results in an error. s={2, 3, 4, [5, 6]}”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 2 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is not the correct syntax for creating a set?
Correct Answer: Option A — set([[1,2],[3,4]])
Detailed Academic Explanation:
set([[1,2],[3,4]]) is the correct answer to “Which of the following is not the correct syntax for creating a set”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 3 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? >>> a={5,6,7,8} >>> b={7,5,6,8} >>> a==b
Correct Answer: Option A — True
Detailed Academic Explanation:
True is the correct answer to “What will be the output of the following Python code? >>> a={5,6,7,8} >>> b={7,5,6,8} >>> a==b”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 4 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following code: set1 = {1, 2, 3} set2 = {2, 3, 4} print(set1.difference(set2))
Correct Answer: Option A — {1}
Detailed Academic Explanation:
{1} is the correct answer to “What is the output of the following code: set1 = {1, 2, 3} set2 = {2, 3, 4} print(set1.difference(set2))”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 5 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Python, how can you check if a set is a subset of another set?
Correct Answer: Option A — issubset()
Detailed Academic Explanation:
issubset() is the correct answer to “In Python, how can you check if a set is a subset of another set”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 6 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? s1={1, 2, 3} s2={4, 5, 6} s1.isdisjoint(s2) s2.isdisjoint(s1)
Correct Answer: Option C — True True
Detailed Academic Explanation:
True True is the correct answer to “What will be the output of the following Python code? s1={1, 2, 3} s2={4, 5, 6} s1.isdisjoint(s2) s2.isdisjoint(s1)”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 7 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? >>> a={1,2,3} >>> b=a.copy() >>> b.add(4) >>> a
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,2,3} >>> b=a.copy() >>> b.add(4) >>> a”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 8 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? s=set() type(s)
Correct Answer: Option B — <class 'set'>
Detailed Academic Explanation:
<class 'set'> is the correct answer to “What will be the output of the following Python code? s=set() type(s)”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 9 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following code: my_set = {1, 2, 3} new_set = my_set.copy() print(new_set)
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 code: my_set = {1, 2, 3} new_set = my_set.copy() print(new_set)”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 10 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Is the following Python code valid? a={3,4,{7,5}} print(a[2][0])
Correct Answer: Option C — Error, subsets aren't allowed
Detailed Academic Explanation:
Error, subsets aren't allowed is the correct answer to “Is the following Python code valid? a={3,4,{7,5}} print(a[2][0])”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 11 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Input order is preserved in sets.
Correct Answer: Option B — False
Detailed Academic Explanation:
False is the correct answer to “Input order is preserved in sets.”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 12 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the copy() method for sets?
Correct Answer: Option A — Creates a shallow copy of the set
Detailed Academic Explanation:
Creates a shallow copy of the set is the correct answer to “What is the purpose of the copy() method for sets”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 13 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Write a list comprehension for number and its cube for: l=[1, 2, 3, 4, 5, 6, 7, 8, 9]
Correct Answer: Option A — [x**3 for x in l]
Detailed Academic Explanation:
[x**3 for x in l] is the correct answer to “Write a list comprehension for number and its cube for: l=[1, 2, 3, 4, 5, 6, 7, 8, 9]”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 14 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following code: set1 = {1, 2} set2 = {1, 2, 3, 4} print(set1.issubset(set2))
Correct Answer: Option A — TRUE
Detailed Academic Explanation:
TRUE is the correct answer to “What is the output of the following code: set1 = {1, 2} set2 = {1, 2, 3, 4} print(set1.issubset(set2))”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 15 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
If we have two sets, s1 and s2, and we want to check if all the elements of s1 are present in s2 or not, we can use the function:
Correct Answer: Option B — s2.issuperset(s1)
Detailed Academic Explanation:
s2.issuperset(s1) is the correct answer to “If we have two sets, s1 and s2, and we want to check if all the elements of s1 are present in s2 or not, we can use the function:”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 16 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python function? {x for x in 'abc'} {x*3 for x in 'abc'}
{‘a’, ‘b’, ‘c’} {‘aaa’, ‘bbb’, ‘ccc’} is the correct answer to “What will be the output of the following Python function? {x for x in 'abc'} {x*3 for x in 'abc'}”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 17 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the syntax of the following Python code? >>> a=frozenset(set([5,6,7])) >>> a
Correct Answer: Option B — frozenset({5,6,7})
Detailed Academic Explanation:
frozenset({5,6,7}) is the correct answer to “What is the syntax of the following Python code? >>> a=frozenset(set([5,6,7])) >>> a”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 18 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What method is used to find the elements that are present in either of the sets, but not in both sets?
Correct Answer: Option A — symmetric_difference()
Detailed Academic Explanation:
symmetric_difference() is the correct answer to “What method is used to find the elements that are present in either of the sets, but not in both sets”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 19 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? >>> a={5,4} >>> b={1,2,4,5} >>> a<b
Correct Answer: Option B — True
Detailed Academic Explanation:
True is the correct answer to “What will be the output of the following Python code? >>> a={5,4} >>> b={1,2,4,5} >>> a<b”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 20 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code, if s1= {1, 2, 3}? s1.issubset(s1)
Correct Answer: Option A — True
Detailed Academic Explanation:
True is the correct answer to “What will be the output of the following Python code, if s1= {1, 2, 3}? s1.issubset(s1)”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 21 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code snippet? {a**2 for a in range(4)}
Correct Answer: Option D — {0, 1, 4, 9}
Detailed Academic Explanation:
{0, 1, 4, 9} is the correct answer to “What will be the output of the following Python code snippet? {a**2 for a in range(4)}”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 22 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The difference between the functions discard and remove is that:
Correct Answer: Option D — Remove throws an error if the specified element is not present in the set whereas discard does not throw an error in case of absence of the specified element
Detailed Academic Explanation:
Remove throws an error if the specified element is not present in the set whereas discard does not throw an error in case of absence of the specified element is the correct answer to “The difference between the functions discard and remove is that:”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 23 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? s1={3, 4} s2={1, 2} s3=set() i=0 j=0 for i in s1: for j in s2: s3.add((i,j)) i+=1 j+=1 print(s3)
{(4, 2), (3, 1), (4, 1), (5, 2)} is the correct answer to “What will be the output of the following Python code? s1={3, 4} s2={1, 2} s3=set() i=0 j=0 for i in s1: for j in s2: s3.add((i,j)) i+=1 j+=1 print(s3)”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 24 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of these about a frozenset is not true?
Correct Answer: Option A — Mutable data type
Detailed Academic Explanation:
Mutable data type is the correct answer to “Which of these about a frozenset is not true”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 25 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? >>> a={1,2,3} >>> {x*2 for x in a|{4,5}}
Correct Answer: Option C — {8, 2, 10, 4, 6}
Detailed Academic Explanation:
{8, 2, 10, 4, 6} is the correct answer to “What will be the output of the following Python code? >>> a={1,2,3} >>> {x*2 for x in a|{4,5}}”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 26 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the difference() method for sets?
Correct Answer: Option A — Returns a new set with elements from the first set that are not in the second set
Detailed Academic Explanation:
Returns a new set with elements from the first set that are not in the second set is the correct answer to “What is the purpose of the difference() method for sets”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 27 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? >>> a={5,6,7,8} >>> b={7,8,10,11} >>> a^b
Correct Answer: Option D — {5,6,10,11}
Detailed Academic Explanation:
{5,6,10,11} is the correct answer to “What will be the output of the following Python code? >>> a={5,6,7,8} >>> b={7,8,10,11} >>> a^b”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 28 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The output of the following code is: class<'set'>. type({})
Correct Answer: Option B — False
Detailed Academic Explanation:
False is the correct answer to “The output of the following code is: class<'set'>. type({})”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 29 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Set members must not be hashable.
Correct Answer: Option B — False
Detailed Academic Explanation:
False is the correct answer to “Set members must not be hashable.”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 30 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? a = [5,5,6,7,7,7] b = set(a) def test(lst): if lst in b: return 1 else: return 0 for i in filter(test, a): print(i,end=" ")
Correct Answer: Option C — 5 5 6 7 7 7
Detailed Academic Explanation:
5 5 6 7 7 7 is the correct answer to “What will be the output of the following Python code? a = [5,5,6,7,7,7] b = set(a) def test(lst): if lst in b: return 1 else: return 0 for i in filter(test, a): print(i,end=" ")”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 31 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following code: set1 = {1, 2, 3} set2 = {3, 4, 5} print(set1.intersection(set2))
Correct Answer: Option A — {3}
Detailed Academic Explanation:
{3} is the correct answer to “What will be the output of the following code: set1 = {1, 2, 3} set2 = {3, 4, 5} print(set1.intersection(set2))”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 32 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following functions will return the symmetric difference between two sets, x and y?
Correct Answer: Option B — x ^ y
Detailed Academic Explanation:
x ^ y is the correct answer to “Which of the following functions will return the symmetric difference between two sets, x and y”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 33 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following code: set1 = {1, 2, 3} set2 = {3, 4, 5} print(set1.union(set2))
Correct Answer: Option A — {1, 2, 3, 4, 5}
Detailed Academic Explanation:
{1, 2, 3, 4, 5} is the correct answer to “What is the output of the following code: set1 = {1, 2, 3} set2 = {3, 4, 5} print(set1.union(set2))”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 34 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Python, how can you create an empty set?
Correct Answer: Option A — set()
Detailed Academic Explanation:
set() is the correct answer to “In Python, how can you create an empty set”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 35 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? s1={1, 2, 3} s2={3, 4, 5, 6} s1.difference(s2) s2.difference(s1)
Correct Answer: Option A — {1, 2} {4, 5, 6}
Detailed Academic Explanation:
{1, 2} {4, 5, 6} is the correct answer to “What will be the output of the following Python code? s1={1, 2, 3} s2={3, 4, 5, 6} s1.difference(s2) s2.difference(s1)”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 36 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? a={1,2,3} b={1,2,3} c=a.issubset(b) print(c)
Correct Answer: Option A — True
Detailed Academic Explanation:
True is the correct answer to “What will be the output of the following Python code? a={1,2,3} b={1,2,3} c=a.issubset(b) print(c)”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 37 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? s={1, 2, 3} s.update(4) s
Correct Answer: Option D — Error
Detailed Academic Explanation:
Error is the correct answer to “What will be the output of the following Python code? s={1, 2, 3} s.update(4) s”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 38 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? >>> a={1,2,3} >>> b=a.add(4) >>> b
Correct Answer: Option D — Nothing is printed
Detailed Academic Explanation:
Nothing is printed is the correct answer to “What will be the output of the following Python code? >>> a={1,2,3} >>> b=a.add(4) >>> b”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 39 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following statements is used to create an empty set?
Correct Answer: Option B — set()
Detailed Academic Explanation:
set() is the correct answer to “Which of the following statements is used to create an empty set”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets In Python
Question 40 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
If a={5,6,7}, what happens when a.add(5) is executed?
Correct Answer: Option B — a={5,6,7}
Detailed Academic Explanation:
a={5,6,7} is the correct answer to “If a={5,6,7}, what happens when a.add(5) is executed”. This question is standard in competitive examination syllabi for Sets In Python.
💡Key Conceptual Anchor:Sets 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.