Python Programming - Sets

Exercise : Sets - General Questions
  • Sets - General Questions
36.
What is the result of the expression set('python').isdisjoint(set('java'))?
True
False
Raises a TypeError
None of the above
Answer: Option
Explanation:
The isdisjoint() method returns True if two sets have no elements in common.

37.
How do you find the elements common to multiple sets?
set.intersection_all()
set.common()
set.common_elements()
set.intersection(*sets)
Answer: Option
Explanation:
The intersection() method with the asterisk (*) operator is used to find common elements in multiple sets.

38.
Which method is used to remove a specific element from a set, raising an error if the element is not present?
set.remove(element)
set.discard(element)
set.exclude(element)
set.delete(element)
Answer: Option
Explanation:
The remove() method removes a specific element, raising an error if the element is not present.

39.
What is the result of the expression set('python') | set('java')?
{'p', 'y', 't', 'h', 'o', 'n', 'j'}
{'p', 'y', 't', 'h', 'o', 'n'}
{'j', 'a', 'v'}
{'j', 'p', 't', 'o', 'h', 'n', 'a', 'y', 'v'}
Answer: Option
Explanation:
The '|' operator performs the union of two sets, combining unique elements.

40.
What is the purpose of the set.symmetric_difference(other_set) method?
Returns the common elements between two sets.
Returns the elements that are unique to each set.
Checks if two sets are equal.
Combines two sets and removes duplicate elements.
Answer: Option
Explanation:
The symmetric_difference() method returns the elements that are unique to each set.