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

1/5

Page

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

Which of the following data types in Python is mutable and does not allow duplicate elements?

Select an option to see the answer and solution.

How can you add an element to a set in Python?

Select an option to see the answer and solution.

Which method is used to remove an element from a set?

Select an option to see the answer and solution.

What does the len() function do when applied to a set or tuple?

Select an option to see the answer and solution.

What is the purpose of the set() constructor in Python?

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

In Python, how can you check if an element exists in a set?

Select an option to see the answer and solution.

What method is used to remove an element from a set without raising an error if the element is not present?

Select an option to see the answer and solution.

What is the output of the following code:
my_set = {1, 2, 3}
print(my_set)

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What is the output of the following code:
my_set = {1, 2, 3}
my_set.remove(2)
print(my_set)

Select an option to see the answer and solution.

Which method is used to find the intersection of two sets?

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What will be the output of the following Python code snippet?
a=[1, 4, 3, 5, 2]
b=[3, 1, 5, 2, 4]
a==b
set(a)==set(b)

Select an option to see the answer and solution.

What will be the output of the following Python code snippet?
s=set([1, 2, 3])
s.union([4, 5])
s|([4, 5])

Select an option to see the answer and solution.

What will be the output of the following Python code?
>>> a={3,4,5}
>>> a.update([1,2,3])
>>> a

Select an option to see the answer and solution.

What is the purpose of the clear() 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,9,10}
>>> len(a+b)

Select an option to see the answer and solution.

If a={5,6,7,8}, which of the following statements is false?

Select an option to see the answer and solution.