Answers for "python adding and subtracting sets"

1

python adding and subtracting sets

a = {10,20,30,40}
b = {30,40,50,60}


print(a & b)
print(a.intersection(b))
#OUTPUT
#{30,40}

print(a | b)
print(a.union(b))
#OUTPUT
#{10,20,30,40,50,60}

print(a - b)
print(a.difference(b))
#OUTPUT
#{10,20}

print(b - a)
print(b.difference(a))
#OUTPUT
#{50,60}
Posted by: Guest on July-17-2021

Python Answers by Framework

Browse Popular Code Answers by Language