gs gs109 Python Sets - Python Sets - Quiz No.6
gs gs109 Python Quiz
This quiz belongs to book/course code gs gs109 Python of gs organization. We have 134 quizzes available related to the book/course Python. This quiz has a total of 10 multiple choice questions (MCQs) to prepare and belongs to topic Python Sets. NVAEducation wants its users to help them learn in an easy way. For that purpose, you are free to prepare online MCQs and quizzes.
NVAEducation also facilitates users to contribute in online competitions with other students to make a challenging situation to learn in a creative way. You can create one to one, and group competition on an topic of a book/course code. Also on NVAEducation you can get certifications by passing the online quiz test.
Question 1: 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)
{(3, 4), (1, 2)}
Error
{(4, 2), (3, 1), (4, 1), (5, 2)}
{(3, 1), (4, 2)}
Question 2: The ____________ function removes the first element of a set and the last element of a list.
remove
pop
discard
dispose
Question 3: The difference between the functions discard and remove is that:
Discard removes the last element of the set whereas remove removes the first element of the set
Discard throws an error if the specified element is not present in the set whereas remove does not throw an error in case of absence of the specified element
Remove removes the last element of the set whereas discard removes the first element of the set
Remove throws an error if the specified element is not present in the set whereas discard does not throw an error in case of absence of the specified element
Question 4: 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)
{1, 2} {4, 5, 6}
{1, 2} {1, 2}
{4, 5, 6} {1, 2}
{4, 5, 6} {4, 5, 6}
Question 5: What will be the output of the following Python code?
s1={1, 2, 3} s2={4, 5, 6} s1.isdisjoint(s2) s2.isdisjoint(s1)
True False
False True
True True
False False
Question 6: 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:
s2.issubset(s1)
s2.issuperset(s1)
s1.issuperset(s2)
s1.isset(s2)
Question 7: 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)
{3} {1, 2, 3, 4, 5, 6, 8}
{1, 2, 4, 5, 6, 8} {1, 2, 4, 5, 6, 8}
{3} {3}
{1, 2, 3, 4, 5, 6, 8} {1, 2, 3, 4, 5, 6, 8}
Question 8: What will be the output of the following Python code?
a=set('abc') b=set('def') b.intersection_update(a) a b
set() (‘e’, ‘d’, ‘f’}
{} {}
{‘b’, ‘c’, ‘a’} set()
set() set()
Question 9: What will be the output of the following Python code, if s1= {1, 2, 3}?
s1.issubset(s1)
True
Error
No output
False
Question 10: What will be the output of the following Python code?
x=set('abcde') y=set('xyzbd') x.difference_update(y) x y
{‘a’, ‘b’, ‘c’, ‘d’, ‘e’} {‘x’, ‘y’, ‘z’}
{‘a’, ‘c’, ‘e’} {‘x’, ‘y’, ‘z’, ‘b’, ‘d’}
{‘b’, ‘d’} {‘b’, ‘d’}
{‘a’, ‘c’, ‘e’} {‘x’, ‘y’, ‘z’}