Vidyalelo
Python · all questions

Python Sets MCQs: Exam
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

90

Questions

4/5

Page

Pick an option on a question to see the right answer and solution.

What will be the output of the following Python code, if s1= {1, 2, 3}?
s1.issubset(s1)

Select an option to see the answer and solution.

What will be the output of the following Python code snippet?
{a**2 for a in range(4)}

Select an option to see the answer and solution.

What will be the output of the following Python code snippet?
z=set('abc$de')
'a' in z

Select an option to see the answer and solution.

The difference between the functions discard and remove is that:

Select an option to see the answer and solution.

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)

Select an option to see the answer and solution.

Which of these about a frozenset is not true?

Select an option to see the answer and solution.

What will be the output of the following Python code?
>>> a={1,2,3}
>>> {x*2 for x in a|{4,5}}

Select an option to see the answer and solution.

What is the purpose of the difference() method for sets?

Select an option to see the answer and solution.

What will be the output of the following Python code?
>>> a={5,6,7,8}
>>> b={7,8,10,11}
>>> a^b

Select an option to see the answer and solution.

The output of the following code is: class<'set'>.
type({})

Select an option to see the answer and solution.

Set members must not be hashable.

Select an option to see the answer and solution.

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=" ")

Select an option to see the answer and solution.

What will be the output of the following code:
set1 = {1, 2, 3}
set2 = {3, 4, 5}
print(set1.intersection(set2))

Select an option to see the answer and solution.

Which of the following functions will return the symmetric difference between two sets, x and y?

Select an option to see the answer and solution.

What is the output of the following code:
set1 = {1, 2, 3}
set2 = {3, 4, 5}
print(set1.union(set2))

Select an option to see the answer and solution.

In Python, how can you create an empty set?

Select an option to see the answer and solution.

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)

Select an option to see the answer and solution.

What will be the output of the following Python code?
a={1,2,3}
b={1,2,3}
c=a.issubset(b)
print(c)

Select an option to see the answer and solution.

What will be the output of the following Python code?
s={1, 2, 3}
s.update(4)
s

Select an option to see the answer and solution.

What will be the output of the following Python code?
>>> a={1,2,3}
>>> b=a.add(4)
>>> b

Select an option to see the answer and solution.