Python Programming - Sets

Exercise : Sets - General Questions
  • Sets - General Questions
41.
What is the result of the expression set([1, 2, 3, 4]).intersection(set([3, 4, 5, 6]))?
{3, 4}
{}
{1, 2, 3, 4, 5, 6}
{1, 2}
Answer: Option
Explanation:
The intersection() method finds the common elements between two sets.

42.
Which method is used to remove and return an arbitrary element from a set?
set.pop()
set.remove()
set.extract()
set.take()
Answer: Option
Explanation:
The pop() method removes and returns an arbitrary element from a set.

43.
How do you find the elements that are unique to each set?
set.symmetric_difference(other_set)
set.difference(other_set)
set.unique_elements(other_set)
set.unique_difference(other_set)
Answer: Option
Explanation:
The symmetric_difference() method returns elements that are unique to each set.

44.
What does the set.symmetric_difference_update(other_set) method do?
Updates the set with common elements.
Removes common elements from the set.
Updates the set with elements unique to the other set.
Returns a new set with the common elements.
Answer: Option
Explanation:
The symmetric_difference_update() method updates the set with elements unique to the other set.

45.
How do you convert a list into a set?
set(list_variable)
list_variable.to_set()
list_variable.as_set()
convert_set(list_variable)
Answer: Option
Explanation:
The set() constructor can be used to convert a list into a set.