Sets MCQs In Python: Pythons Language Sets MCQs

Sets MCQs In Python. Multiple Choice Questions related to sets in Python.

Sets MCQs In Python

 

 

If a={5,6,7}, what happens when a.add(5) is executed ??

a) a={5,5,6,7}
b) a={5,6,7}
c) Error as there is no add function for set data type
d) Error as 5 already exists in the set

 

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

>>> a={1,2,3}
>>> b=a
>>> b.remove(3)
>>> a

a) {1,2,3}
b) Error, copying of sets isn’t allowed
c) {1,2}
d) Error, invalid syntax for remove

 

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

a) print(len(a))
b) print(min(a))
c) a.remove(5)
d) a[2]=45

 

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

>>> a={1,2,3}
>>> a.intersection_update({2,3,4,5})
>>> a

a) {2,3}
b) Error, duplicate item present in list
c) Error, no method called intersection_update for set data type
d) {1,4,5}

 

Sets MCQs In Python

 

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

>>> a={5,4}
>>> b={1,2,4,5}
>>> a<b

a) {1,2}
b) True
c) False
d) Invalid operation

 

What will be the output of the following Python ??

>>> a={3,4,5}
>>> a.update([1,2,3])
>>> a

a) Error, no method called update for set data type
b) {1, 2, 3, 4, 5}
c) Error, list can’t be added to set
d) Error, duplicate item present in list

 

Which of the following statements is used to create an empty set ??

a) { }
b) set()
c) [ ]
d) ( )

 

Set members must not be hashable ??

a) True
b) False

 

Sets MCQs In Python

 

What will be the output of the following code ??

a = [5,5,6,7,7,7]
b = set(a)
def test(lst):
if lst in b:
return 1
else:
return 0
for i in filter(test, a):
print(i,end=” “)

a) 5 5 6
b) 5 6 7
c) 5 5 6 7 7 7
d) 5 6 7 7 7

 

Is the following Python code valid ??

>>> a=frozenset([5,6,7])
>>> a
>>> a.add(5)

a) Yes, now a is {5,5,6,7}
b) No, frozen set is immutable
c) No, invalid syntax for add method
d) Yes, now a is {5,6,7}

 

What will be the output of the following ??

nums = set([1,1,2,3,3,3,4,4])
print(len(nums))

a) 7
b) Error, invalid syntax for formation of set
c) 4
d) 8

 

What is the syntax of the following Python code ??

>>> a=frozenset(set([5,6,7]))
>>> a

a) {5,6,7}
b) frozenset({5,6,7})
c) Error, not possible to convert set into frozenset
d) Syntax error

 

Sets MCQs In Python

 

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

a) set([[1,2],[3,4]])
b) set([1,2,2,3,4])
c) set((1,2,3,4))
d) {1,2,3,4}

 

Which of these about a frozenset is not true ??

a) Mutable data type
b) Allows duplicate values
c) Data type with unordered values
d) Immutable data type

 

Which of these about a set is not true ??

a) Mutable data type
b) Allows duplicate values
c) Data type with unordered values
d) Immutable data type

Leave a Comment

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

error: Content is protected !!