What will be the output of the following Python code?
a) True
b) False
Explanation: It is possible to compare two sets and the order of elements in both the sets doesn’t matter if the values of the elements are the same.
What will be the output of the following Python code?
a) Invalid operation
b) {3, 4, 5, 6, 7}
c) {5}
d) {3,4,6,7}
Explanation: The operation in the above piece of code is union operation. This operation produces a set of elements in both set a and set b.
Is the following Python code valid?
a) Yes, 7 is printed
b) Error, elements of a set can’t be printed
c) Error, subsets aren’t allowed
d) Yes, {7,5} is printed
Explanation: In python, elements of a set must not be mutable and sets are mutable. Thus, subsets can’t exist.
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
Explanation: A frozenset is an immutable data type.
What is the syntax of the following Python code?
a) {5,6,7}
b) frozenset({5,6,7})
c) Error, not possible to convert set into frozenset
d) Syntax error
Explanation: The above piece of code is the correct syntax for creating a frozenset.
Is the following Python code valid?
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}
Explanation: Since a frozen set is immutable, add method doesn’t exist for frozen method.