how to get union of two sets in python symbol code example

Example 1: set except python

# Program to perform different set operations 
# as we do in  mathematics 
  
# sets are define 
A = {0, 2, 4, 6, 8}; 
B = {1, 2, 3, 4, 5}; 
  
# union 
print("Union :", A | B) 
  
# intersection 
print("Intersection :", A & B) 
  
# difference 
print("Difference :", A - B) 
  
# symmetric difference 
print("Symmetric difference :", A ^ B)

Example 2: .union in python

set1 = {2, 4, 5, 6}  
set2 = {4, 6, 7, 8}  
set3 = {7, 8, 9, 10} 
  
# union of two sets 
print("set1 U set2 : ", set1.union(set2)) 
  
# union of three sets 
print("set1 U set2 U set3 :", set1.union(set2, set3))