Which method is used to combine two sets in Python?
A
merge() B
add() C
union() D
append()
Analysis & Theory
`union()` returns a new set containing all unique elements from both sets.
What does the `update()` method do when used on a set?
A
It replaces the set B
It adds elements from another set C
It deletes duplicates D
It joins sets into a list
Analysis & Theory
`update()` adds elements from another set (or iterable) into the current set.
What will this output?
a = {1, 2}
b = {2, 3}
c = a.union(b)
print(c)
A
{1, 2, 3} B
{1, 2, 2, 3} C
[1, 2, 3] D
Error
Analysis & Theory
`union()` combines both sets and removes duplicates → `{1, 2, 3}`.
What happens to duplicate values when joining two sets?
A
They are kept B
They are removed automatically C
They raise an error D
They are merged into a tuple
Analysis & Theory
Sets automatically discard duplicates when joined.
Which of these is a valid way to join sets using an operator?
A
set1 + set2 B
set1 & set2 C
set1 | set2 D
set1 * set2
Analysis & Theory
`|` (pipe) operator performs union between sets.
Which method modifies the original set with new items from another?
A
copy() B
union() C
update() D
add()
Analysis & Theory
`update()` adds all elements from another iterable to the current set.
What is the difference between `union()` and `update()`?
A
`union()` modifies original set, `update()` returns a new one B
`union()` returns new set, `update()` modifies original C
They are exactly the same D
Both return lists
Analysis & Theory
`union()` returns a new set, while `update()` modifies the original set in-place.
Which of these joins multiple sets into one new set?
A
set1.append(set2) B
set1.union(set2, set3) C
set1.join(set2, set3) D
set1 + set2 + set3
Analysis & Theory
`union()` can accept multiple sets to join at once.
What will be the result of this code?
a = {1, 2}; b = {3, 4}; a.update(b)
print(a)
A
{1, 2} B
{3, 4} C
{1, 2, 3, 4} D
[1, 2, 3, 4]
Analysis & Theory
`update()` modifies `a` by adding items from `b`.
Can you join a set with a list using `update()`?
A
No, only sets can be joined B
Yes, if the list has only unique items C
Yes, because `update()` accepts any iterable D
Only in Python 2
Analysis & Theory
`update()` accepts any iterable (like a list, tuple, or set).