Contents

What will be the output of the following Python code?
a) {1,2}
b) Error as difference between a set and frozenset can’t be found out
c) Error as unsupported operand type for set data type
d) frozenset({1,2})

a

Explanation: operator gives the set of elements in set a but not in set b.


What will be the output of the following Python code?
a) 5                                                        
b) 23
c) 18
d) Invalid syntax for sum method, too many arguments

b

Explanation: The second parameter is the start value for the sum of elements in set a. Thus, sum(a,5) = 5+(5+6+7)=23.


What will be the output of the following Python code?
a) {2,4,6}
b) Error, set comprehensions aren’t allowed
c) {8, 2, 10, 4, 6} 
d) {8,10}

c

Explanation: Set comprehensions are allowed.


What will be the output of the following Python code?
a) 8
b) Error, unsupported operand ‘+’ for sets
c) 6
d) Nothing is displayed

b

Explanation: Duplicate elements in a+b is eliminated and the length of a+b is computed.


What will be the output of the following Python code?
a) True
b) Error, no method called issubset() exists
c) Syntax error for issubset() method
d) False

a

Explanation: The method issubset() returns True if b is a proper subset of a.


Is the following Python code valid?
a) False                                
b) True
c) Syntax error for issuperset() method
d) Error, no method called issuperset() exists

a

Explanation: The method issubset() returns True if b is a proper subset of a.