Python Programming - Sets

Exercise : Sets - General Questions
  • Sets - General Questions
21.
What does the set.symmetric_difference_update(other_set) method do?
Updates the set with elements from another set.
Removes elements common to both sets.
Returns the symmetric difference between two sets.
Modifies the set with elements unique to each set.
Answer: Option
Explanation:
The symmetric_difference_update() method modifies the set with elements unique to each set.

22.
What is the result of the expression len(set("python"))?
5
6
7
Raises a TypeError
Answer: Option
Explanation:
The set("python") creates a set of unique characters, and the length is 6.

23.
Which method is used to update a set with elements from another set or iterable?
set.merge(other_set)
set.append(other_set)
set.update(other_set)
set.combine(other_set)
Answer: Option
Explanation:
The update() method is used to update a set with elements from another set or iterable.

24.
What is the result of the expression set([1, 2, 3]) & set([2, 3, 4])?
{1, 2, 3, 4}
{2, 3}
{}
{1, 4}
Answer: Option
Explanation:
The '&' operator performs the intersection of two sets, giving elements common to both sets.

25.
Which method is used to remove and return the last element from a set?
set.pop()
set.remove_last()
set.delete_last()
set.discard_last()
Answer: Option
Explanation:
The pop() method removes and returns an arbitrary element, which is the last element in a set.