Python Programming - Sets

Exercise : Sets - General Questions
  • Sets - General Questions
31.
Which method is used to find the intersection of multiple sets?
set.intersect_all()
set.intersection_update()
set.intersect()
set.intersect_many()
Answer: Option
Explanation:
The intersection_update() method is used to find the intersection of multiple sets.

32.
How do you remove a specific element from a set without raising an error if the element is not present?
set.delete(element)
set.remove(element)
set.discard(element)
set.exclude(element)
Answer: Option
Explanation:
The discard() method removes a specific element without raising an error if the element is not present.

33.
What is the purpose of the set.copy() method?
Creates a shallow copy of the set.
Creates a deep copy of the set.
Creates an identical copy of the set.
Creates a reversed copy of the set.
Answer: Option
Explanation:
The copy() method creates a shallow copy of the set.

34.
What is the result of the expression len(set())?
0
1
Raises a TypeError
None of the above
Answer: Option
Explanation:
An empty set has a length of 0.

35.
What does the set.union(other_set) method do?
Finds the common elements between two sets.
Combines two sets and removes duplicate elements.
Returns the elements that are unique to each set.
Checks if two sets are equal.
Answer: Option
Explanation:
The union() method combines two sets and removes duplicate elements.