gs gs109 Python Sets - Python Sets - Quiz No.2
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?
>>> a={5,6,7,8} >>> b={7,8,10,11} >>> a^b
{5,6,7,8,10,11}
{7,8}
Error as unsupported operand type of set data type
{5,6,10,11}
Question 2: What will be the output of the following Python code?
>>> s={5,6} >>> s*3
Error as unsupported operand type for set data type
{5,6,5,6,5,6}
{5,6}
Error as multiplication creates duplicate elements which isn’t allowed
Question 4: What will be the output of the following Python code?
>>> a={3,4,5} >>> b={5,6,7} >>> a|b
Invalid operation
{3, 4, 5, 6, 7}
{5}
{3,4,6,7}
Question 5: Is the following Python code valid?
a={3,4,{7,5}} print(a[2][0])
Yes, 7 is printed
Error, elements of a set can’t be printed
Error, subsets aren’t allowed
Yes, {7,5} is printed
Question 6: Which of these about a frozenset is not true?
Mutable data type
Allows duplicate values
Data type with unordered values
Immutable data type
Question 7: What is the syntax of the following Python code?
>>> a=frozenset(set([5,6,7])) >>> a
{5,6,7}
frozenset({5,6,7})
Error, not possible to convert set into frozenset
Syntax error
Question 8: Is the following Python code valid?
>>> a=frozenset([5,6,7]) >>> a >>> a.add(5)
Yes, now a is {5,5,6,7}
No, frozen set is immutable
No, invalid syntax for add method
Yes, now a is {5,6,7}
Question 10: What will be the output of the following Python code?
>>> a={3,4,5} >>> a.update([1,2,3]) >>> a
Error, no method called update for set data type
{1, 2, 3, 4, 5}
Error, list can’t be added to set
Error, duplicate item present in list