Sets In Python
This section focuses on the "Set" in Python. These Multiple Choice Questions (mcq) should be practiced to improve the Python skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.
1. Which of the following Python code will create a set?
(i) set1=set((0,9,0))
(ii) set1=set([0,2,9])
(iii) set1={}
View Answer
2. What will be the output of following Python code?
set1={0,0,9}
print(set1)
View Answer
3. What will be the output of following Python code?
set1={2,5,3}
set2={3,1}
set3={}
set3=set1&set2
print(set3)
View Answer
4. What will be the output of following Python code?
list1=[1,3,4,2]
x=list1.pop(2)
print(set([x]))
View Answer
5. What will set1|set2 do?
If set1={"a","b",3}
set2={3,7}
View Answer
6. What will the below Python code do?
set1={"a",3,"b",3}
set1.remove(3)
View Answer
7. What will the below Python code do?
set1={2,3}
set2={3,2}
set3={2,1}
if(set1==set2):
print("yes")
else:
print("no")
if(set1==set3):
print("yes")
else:
print("no")
View Answer
8. Suppose there are two sets, set1 and set2,where set1 is the superset of set2. It is required to get only the unique elements of both the sets. Which of the following will serve the purpose?
set1={2,3}
set2={3,2}
set3={2,1}
if(set1==set2):
print("yes")
else:
print("no")
if(set1==set3):
print("yes")
else:
print("no")
View Answer
9. What will the be the result of below Python code?
set1={1,2,3}
set1.add(4)
set1.add(4)
print(set1)
View Answer
10. Which of the following options will give an error if set1={2,3,4,5}?
View Answer
Discussion