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

2/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?
>>> s={5,6}
>>> s*3

Select an option to see the answer and solution.

In Python, how can you check if two sets have no elements in common?

Select an option to see the answer and solution.

What will be the output of the following Python code?
s={4>3, 0, 3-3}
all(s)
any(s)

Select an option to see the answer and solution.

What will be the output of the following Python code snippet?
z=set('abc')
z.add('xyz')
z.update(set(['p', 'q']))
z

Select an option to see the answer and solution.

What will be the output of the following Python code?
>>> a={5,6,7}
>>> sum(a,5)

Select an option to see the answer and solution.

What will be the output of the following Python code?
x=set('abcde')
y=set('xyzbd')
x.difference_update(y)
x
y

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

In Python, how can you check if two sets have no elements in common?

Select an option to see the answer and solution.

What will be the output of the following Python code snippet?
l=[1, 2, 4, 5, 2, 'xy', 4]
set(l)
l

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

Is the following Python code valid?
>>> a=frozenset([5,6,7])
>>> a
>>> a.add(5)

Select an option to see the answer and solution.

What will be the output of the following Python code?
s1={1, 2, 3, 8}
s2={3, 4, 5, 6}
s1|s2
s1.union(s2)

Select an option to see the answer and solution.

Which of these about a set is not true?

Select an option to see the answer and solution.

What will be the output of the following Python code?
a=set('abc')
b=set('def')
b.intersection_update(a)
a
b

Select an option to see the answer and solution.

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

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
>>> b.remove(3)
>>> a

Select an option to see the answer and solution.

The . . . . . . . . function removes the first element of a set and the last element of a list.

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

Which of the following lines of code will result in an error?

Select an option to see the answer and solution.