Sets in Python

Source code :

myset1={1,2,4,2,5,3,6,3,'a','v','g','x'}
myset2={7,8,9,4,10,3,4,'b','h','a','x','r'}
print("union:",myset1 | myset2)
print("intersection:",myset1&myset2)
print("difference:",myset1-myset2)

Output :

union: {1, 2, 3, 4, 5, 6, 'r', 7, 8, 'g', 9, 10, 'h', 'v', 'b', 'a', 'x'}
intersection: {'a', 3, 4, 'x'}
difference: {1, 2, 5, 6, 'g', 'v'}

Output :


                

Comments :