# Define two sets
set_a = {1, 2, 3, 4}
set_b = {3, 4, 5, 6}
# dd an element to the set
set_a.add(5)
print("After add(5):", set_a)
# Remove an element (raises an error if the element is not found)
set_a.remove(5)
print("After remove(5):", set_a)
# Remove an element (doesn't raise an error if not found)
set_a.discard(6) # No error even if 6 is not in set_a
print("After discard(6):", set_a)
# Remove all elements from the set
temp_set = set_a.copy() # Make a copy to preserve the original
temp_set.clear()
print("After clear():", temp_set)
# Remove and return an arbitrary element
popped_element = set_a.pop()
print("After pop():", set_a, "| Popped element:", popped_element)
# Combine elements from both sets (returns a new set)
union_set = set_a.union(set_b)
print("Union of set_a and set_b:", union_set)
# 7. Find common elements between sets (returns a new set)
intersection_set = set_a.intersection(set_b)
print("Intersection of set_a and set_b:", intersection_set)
# Find elements in set_a but not in set_b
difference_set = set_a.difference(set_b)
print("Difference (set_a - set_b):", difference_set)
# Find elements in either set_a or set_b but not both
symmetric_difference_set = set_a.symmetric_difference(set_b)
print("Symmetric difference of set_a and set_b:", symmetric_difference_set)
# Add elements from set_b to set_a
set_a.update(set_b)
print("After update(set_b):", set_a)
# Check if set_a is a subset of set_b
print("Is set_a a subset of union_set?", set_a.issubset(union_set))
# Check if set_a is a superset of set_b
print("Is set_a a superset of set_b?", set_a.issuperset(set_b))
# Check if set_a and set_b have no elements in common
print("Are set_a and set_b disjoint?", set_a.isdisjoint(set_b))