Sets Question Python: Python MCQs on Sets

Sets Question Python. MCQs related to sets in Python Language.

 

Sets Question Python

 

 

What will be the output of the following Python code ??

x=set(‘abcde’)
y=set(‘xyzbd’)
x.difference_update(y)
x
y

a) {‘a’, ‘b’, ‘c’, ‘d’, ‘e’}
{‘x’, ‘y’, ‘z’}

b) {‘a’, ‘c’, ‘e’}
{‘x’, ‘y’, ‘z’, ‘b’, ‘d’}

c) {‘b’, ‘d’}
{‘b’, ‘d’}

d) {‘a’, ‘c’, ‘e’}
{‘x’, ‘y’, ‘z’}

 

What will be the output of the following Python code snippet ??

l=[1, 2, 4, 5, 2, ‘xy’, 4]
set(l)
l

a) {1, 2, 4, 5, 2, ‘xy’, 4}
[1, 2, 4, 5, 2, ‘xy’, 4]

b) {1, 2, 4, 5, ‘xy’}
[1, 2, 4, 5, 2, ‘xy’, 4]

c) {1, 5, ‘xy’}
[1, 5, ‘xy’]

d) {1, 2, 4, 5, ‘xy’}
[1, 2, 4, 5, ‘xy’]

 

What will be the output of the following Python code ??

s={4>3, 0, 3-3}
all(s)
any(s)

a) True
False

b) False
True

c) True
True

d) False
False

 

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

s1.issubset(s1)

a) True
b) Error
c) No output
d) False

 

Sets Question Python

 

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)

a) True
False

b) False
False

c) False
True

d) True
True

 

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

a) pop
b) remove
c) update
d) sum

 

What will be the output of the following Python code ??

a=set(‘abc’)
b=set(‘def’)
b.intersection_update(a)
a
b

a) set()
(‘e’, ‘d’, ‘f’}

b) {}
{}

c) {‘b’, ‘c’, ‘a’}
set()

d) set()
set()

 

The output of the following code is: class<’set’> ??

type({})

a) True
b) False

 

Sets Question Python

 

What will be the output of the following Python code ??

s={1, 2, 3}
s.update(4)
s

a) {1, 2, 3, 4}
b) {1, 2, 4, 3}
c) {4, 1, 2, 3}
d) Error

 

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)

a) {3}
{1, 2, 3, 4, 5, 6, 8}

b) {1, 2, 4, 5, 6, 8}
{1, 2, 4, 5, 6, 8}

c) {3}
{3}

d) {1, 2, 3, 4, 5, 6, 8}
{1, 2, 3, 4, 5, 6, 8}

 

What will be the output of the following Python function ??

{x for x in ‘abc’}
{x*3 for x in ‘abc’}

a) {abc}
aaa
bbb
ccc

b) abc
abc abc abc

c) {‘a’, ‘b’, ‘c’}
{‘aaa’, ‘bbb’, ‘ccc’}

d) {‘a’, ‘b’, ‘c’}
abc
abc
abc

 

Write a list comprehension for number and its cube for ??

l=[1, 2, 3, 4, 5, 6, 7, 8, 9]

a) [x**3 for x in l]
b) [x^3 for x in l]
c) [x**3 in l]
d) [x^3 in l]

 

Sets Question Python

 

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 ??

a) s2.issubset(s1)
b) s2.issuperset(s1)
c) s1.issuperset(s2)
d) s1.isset(s2)

 

What will be the output of the following Python code snippet ??

{a**2 for a in range(4)}

a) {1, 4, 9, 16}
b) {0, 1, 4, 9, 16}
c) Error
d) {0, 1, 4, 9}

 

Input order is preserved in sets ??

a) True
b) False

Leave a Comment

Your email address will not be published. Required fields are marked *

error: Content is protected !!