How to Join Two Or More Sets in Python


In this example we will show how to join two or more sets using the union() method in Python.

Source Code

set1 = {'apple', 'banana', 'orange'}
set2 = {'cow', 'sheep', 'pig'}

set3 = set1.union(set2)
print(set3)

Output:

{'cow', 'apple', 'banana', 'pig', 'sheep', 'orange'}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments