728x90
# add() 요소 추가
my_set = {10, 20, 30}
my_set.add(40)
# {10, 20, 30, 40}
# remove() 요소 삭제
my_set = {10, 20, 30}
my_set.remove(10)
# {20, 30}
# Intersection (교집합)
set1 = {3, 4, 9, 1, 4, 2, 5, 6, 7, 8, 10}
set2 = {5, 6, 7, 8, 9, 10}
# {5, 6, 7, 8, 9, 10}
# Union (합집합)
set1 = {3, 4, 9, 1, 4, 2, 5, 6, 7, 8, 10}
set2 = {5, 6, 7, 8, 9, 10}
print(set1 | set2)
print(set1.union(set2))
# {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
728x90