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

3/5

Page

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

Which of the following functions cannot be used on heterogeneous sets?

Select an option to see the answer and solution.

The following Python code results in an error.
s={2, 3, 4, [5, 6]}

Select an option to see the answer and solution.

Which of the following is not the correct syntax for creating a set?

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,5,6,8}
>>> a==b

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

In Python, how can you check if a set is a subset of another 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={4, 5, 6}
s1.isdisjoint(s2)
s2.isdisjoint(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=a.copy()
>>> b.add(4)
>>> a

Select an option to see the answer and solution.

What will be the output of the following Python code?
s=set()
type(s)

Select an option to see the answer and solution.

What will be the output of the following code:
my_set = {1, 2, 3}
new_set = my_set.copy()
print(new_set)

Select an option to see the answer and solution.

Is the following Python code valid?
a={3,4,{7,5}}
print(a[2][0])

Select an option to see the answer and solution.

Input order is preserved in sets.

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

Write a list comprehension for number and its cube for:
l=[1, 2, 3, 4, 5, 6, 7, 8, 9]

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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:

Select an option to see the answer and solution.

What will be the output of the following Python function?
{x for x in 'abc'}
{x*3 for x in 'abc'}

Select an option to see the answer and solution.

What is the syntax of the following Python code?
>>> a=frozenset(set([5,6,7]))
>>> a

Select an option to see the answer and solution.

What method is used to find the elements that are present in either of the sets, but not in both sets?

Select an option to see the answer and solution.

What will be the output of the following Python code?
>>> a={5,4}
>>> b={1,2,4,5}
>>> a<b

Select an option to see the answer and solution.