Python Programming - Sets

Exercise : Sets - General Questions
  • Sets - General Questions
26.
What is the purpose of the set.isdisjoint(other_set) method?
Checks if two sets are equal.
Checks if two sets have no elements in common.
Checks if one set is a subset of another.
Checks if one set is a superset of another.
Answer: Option
Explanation:
The isdisjoint() method checks if two sets have no elements in common.

27.
What is the result of the expression set('abc') ^ set('cde')?
{'a', 'b', 'c', 'd', 'e'}
{'a', 'b'}
{'c'}
{'a', 'b', 'd', 'e'}
Answer: Option
Explanation:
The '^' operator performs the symmetric difference, giving elements that are unique to each set.

28.
What is the result of the expression set('programming') - set('python')?
{'r', 'g', 'a', 'm', 'i'}
{'p', 'y', 't'}
{'r', 'o', 'm', 'i', 'n'}
{'p', 'r', 'o', 'g', 'a', 'm', 'i', 'n'}
Answer: Option
Explanation:
The '-' operator performs the set difference, giving elements that are in the first set but not in the second.

29.
Which method is used to check if a set is equal to another set?
set.is_equal(other_set)
set.equals(other_set)
set.is_equal_to(other_set)
set == other_set
Answer: Option
Explanation:
The '==' operator is used to check if two sets are equal.

30.
What is the purpose of the set.add(element) method?
Adds an element to the end of the set.
Adds an element to the specified index in the set.
Adds an element to the beginning of the set.
Adds an element to the set.
Answer: Option
Explanation:
The add() method is used to add an element to the set.