Contents

If a={5,6,7,8}, which of the following statements is false?
a) print(len(a))                     
b) print(min(a))
c) a.remove(5)                     
d) a[2]=45

d

Explanation: The members of a set can be accessed by their index values since the elements of the set are unordered.


If a={5,6,7}, what happens when a.add(5) is executed?
a) a={5,5,6,7}                     
b) a={5,6,7}
c) Error as there is no add function for set data type
d) Error as 5 already exists in the set

b

Explanation: There exists add method for set data type. However 5 isn’t added again as set consists of only non-duplicate elements and 5 already exists in the set. Execute in python shell to verify.


What will be the output of the following Python code?
a) {4,5,6,2,8}                       
b) {4,5,6,2,8,6}
c) Error as unsupported operand type for sets
d) Error as the duplicate item 6 is present in both sets

c

Explanation: Execute in python shell to verify.


What will be the output of the following Python code?
a) {4,5}                                 
b) {6}
c) Error as unsupported operand type for set data type
d) Error as the duplicate item 6 is present in both sets

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,6,7,8,10,11}               
b) {7,8}
c) Error as unsupported operand type of set data type
d) {5,6,10,11}

d

Explanation: ^ operator returns a set of elements in set A or set B, but not in both (symmetric difference).


What will be the output of the following Python code?
a) Error as unsupported operand type for set data type
b) {5,6,5,6,5,6}    
c) {5,6}
d) Error as multiplication creates duplicate elements which isn’t allowed

b

Explanation: The multiplication operator isn’t valid for the set data type.