Write a program to perform below operations on set: ● Create two different sets with the data. ● Print set items. ● Add/remove items in/from a set. ● Perform operations on sets: union, intersection, difference, symmetric difference, check subset of another set.

 

set1 = {1,3.14,12,'two'}
set2 = {1,2,3,'mrcoder'}

print(set1)
print(set2)

set1.remove(3.14)
set2.add(4)

print(set1)
print(set2)

print(set1.union(set2))

print(set1.intersection(set2))

print(set1.difference(set2))

print(set1.symmetric_difference(set2))

print(set1.issubset(set2))

output:
{1, 3.14, 12, 'two'}
{'mrcoder', 1, 2, 3}
{1, 12, 'two'}
{1, 2, 3, 4, 'mrcoder'}
{1, 2, 3, 4, 'two', 12, 'mrcoder'}
{1}
{12, 'two'}
{2, 3, 4, 'two', 'mrcoder', 12}
False

Comments