028-002. set operator, union(OR, |), intersection(AND, &), difference(-), symmetric difference(XOR, ^)
@
# set operators use arithmetic operator and logical operator of Python
@
a = {1, 2, 3, 4}
b = {3, 4, 5, 6}
# I make union set
print(a | b)
# {1, 2, 3, 4, 5, 6}
@
a = {1, 2, 3, 4}
b = {3, 4, 5, 6}
# I make intersection set
print(a & b)
# {3, 4}
@
a = {1, 2, 3, 4}
b = {3, 4, 5, 6}
# I make difference set
print(a - b)
# {1, 2}
@
a = {1, 2, 3, 4}
b = {3, 4, 5, 6}
# I make symmetric difference by using XOR(^)
print(a ^ b)
# {1, 2, 5, 6}
@
a = {1, 2, 3, 4}
# a = a | {5}
a |= {5}
print(a)
# {1, 2, 3, 4, 5}