Contents

Set members must not be hashable.
a) True                                  
b) False

b

Explanation: Set members must always be hashable.


What will be the output of the following Python code?
a) Error, no method called update for set data type
b) {1, 2, 3, 4, 5}
c) Error, list can’t be added to set
d) Error, duplicate item present in list

b

Explanation: The method update adds elements to a set.


What will be the output of the following Python code?
a) {2,3}
b) Error, duplicate item present in list
c) Error, no method called intersection_update for set data type
d) {1,4,5}

a

Explanation: The method intersection_update returns a set which is an intersection of both the sets.


What will be the output of the following Python code?
a) {1,2,3}
b) Error, copying of sets isn’t allowed
c) {1,2}
d) Error, invalid syntax for remove

c

Explanation: Any change made in b is reflected in a because b is an alias of a.


What will be the output of the following Python code?
a) {1,2,3}
b) Error, invalid syntax for add
c) {1,2,3,4}
d) Error, copying of sets isn’t allowed

a

Explanation: In the above piece of code, b is barely a copy and not an alias of a. Hence any change made in b isn’t reflected in a.


What will be the output of the following Python code?
a) 0                                                        
b) {1,2,3,4}
c) {1,2,3}              
d) Nothing is printed

d

Explanation: The method add returns nothing, hence nothing is printed.