In your example, set.union(set1, set2)
actually calls the union
method with set1
for the self
argument. Therefore, it is equivalent to set1.union(set2)
.
As an aside, Python allows union-ing of arbitrary numbers of sets according to this. Actually you can see this in the Python documentation, here. Because the union
method accepts *others
as an argument, you can pass in any number of sets and it will perform the union of all of them.
set1 = {1, 2, 3, 4}
set2 = {1, 3, 4, 5}
set3 = {2, 4, 6, 7}
print(set.union(set1, set2, set))
# {1, 2, 3, 4, 5, 6, 7}