Exercise: Python

Questions for: Sets

Which method is used to update a set with elements from another set or iterable?
A:
set.merge(other_set)
B:
set.append(other_set)
C:
set.update(other_set)
D:
set.combine(other_set)
Answer: C
The update() method is used to update a set with elements from another set or iterable.
What is the result of the expression len(set("python"))?
A:
5
B:
6
C:
7
D:
Raises a TypeError
Answer: B
The set("python") creates a set of unique characters, and the length is 6.
What does the set.symmetric_difference_update(other_set) method do?
A:
Updates the set with elements from another set.
B:
Removes elements common to both sets.
C:
Returns the symmetric difference between two sets.
D:
Modifies the set with elements unique to each set.
Answer: D
The symmetric_difference_update() method modifies the set with elements unique to each set.
Which of the following statements about frozensets in Python is correct?
A:
Frozensets are mutable.
B:
Frozensets can be used as dictionary keys.
C:
Frozensets can be modified after creation.
D:
Frozensets support element removal using the remove() method.
Answer: B
Frozensets are immutable and can be used as dictionary keys or elements of other sets.
Which method is used to find the union of two sets?
A:
set.combine(other_set)
B:
set.union(other_set)
C:
set.merge(other_set)
D:
set.join(other_set)
Answer: B
The union() method is used to find the union of two sets.
Ad Slot (Above Pagination)
Quiz