Python MCQs on Sets: Python Programming Sets MCQs

Python MCQs on Sets. Sets MCQs in Python Programming Language.

 

Python MCQs on Sets

 

 

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

s1={1, 2, 3}
s2={4, 5, 6}
s1.isdisjoint(s2)
s2.isdisjoint(s1)

a) True
False

b) False
True

c) True
True

d) False
False

 

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

for x in set(‘pqr’):
print(x*2)

a) pp
qq
rr

b) pqr
pqr

c) ppqqrr

d) pqrpqr

 

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

s={2, 5, 6, 6, 7}
s

a) {2, 5, 7}
b) {2, 5, 6, 7}
c) {2, 5, 6, 6, 7}
d) Error

 

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)

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

b) {1, 2}
{1, 2}

c) {4, 5, 6}
{1, 2}

d) {4, 5, 6}
{4, 5, 6}

 

Python MCQs on Sets

 

 

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

s=set([1, 2, 3])
s.union([4, 5])
s|([4, 5])

 

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

b) Error
{1, 2, 3, 4, 5}

c) {1, 2, 3, 4, 5}
Error

d) Error
Error

 

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

a) s={abs}
b) s={4, ‘abc’, (1,2)}
c) s={2, 2.2, 3, ‘xyz’}
d) s={san}

 

The difference between the functions discard and remove is that ??

a) Discard removes the last element of the set whereas remove removes the first element of the set
b) Discard throws an error if the specified element is not present in the set whereas remove does not throw an error in case of the absence of the specified element
c) Remove removes the last element of the set whereas discard removes the first element of the set
d) Remove throws an error if the specified element is not present in the set whereas discard does not throw an error in case of the absence of the specified element

 

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

z=set(‘abc’)
z.add(‘san’)
z.update(set([‘p’, ‘q’]))
z

a) {‘abc’, ‘p’, ‘q’, ‘san’}
b) {‘a’, ‘b’, ‘c’, [‘p’, ‘q’], ‘san}
c) {‘a’, ‘c’, ‘c’, ‘p’, ‘q’, ‘s’, ‘a’, ‘n’}
d) {‘a’, ‘b’, ‘c’, ‘p’, ‘q’, ‘san’}

 

Python MCQs on Sets

 

Set makes use of ? Dictionary makes use of ??

a) keys, keys
b) key values, keys
c) keys, key values
d) key values, key values

 

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

a) remove
b) pop
c) discard
d) dispose

 

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

z=set(‘abc$de’)
‘a’ in z

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

 

The following Python code results in an error ??

s={2, 3, 4, [5, 6]}

a) True
b) False

 

Python MCQs on Sets

 

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)

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

 

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

a) x | y
b) x ^ y
c) x & y
d) x – y

 

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

s=set()
type(s)

a) <’set’>
b) <class ‘set’>
c) set
d) class set

Leave a Comment

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

error: Content is protected !!