Python Program to Demonstate Different Set Operations

odd=set([x*2+1 for x in range(1,10)])
print("Odd Numbers:", odd)
prime=set()
for i in range(2,25):
j=2
flag=0
while j<i/2:
if i%j==0:
flag=1
j+=1
if flag==0:
prime.add(i)
print("Prime Numbers:", prime)
print("Union:", odd.union(prime))
print("Intersection:", odd.intersection(prime))
print("Symmetric Difference:", odd.symmetric_difference(prime))
print("Difference:", odd.difference(prime))

 

Output:
Python Program to Demonstate Different Set Operations