Student name- Sachin Page no-3
Roll no- 48 D.O.P-26/08/2025
Course- BCA AI&DS
PROBLEM STATEMENT 3- Write a python program to implement set operation.
OBJECTIVE- To understand the implementation of various set operation.
EXPLANATION- A set operation is a mathematical action on two or more sets that
Produces a new set by combining, comparing, or modifying the elements of the
original sets.
SOURCE CODE-
# Creating two sets
A = {1, 2, 3, 4, 5}
B = {4, 5, 6, 7, 8}
print("Set A:", A)
print("Set B:", B)
# Union
print("\nUnion of A and B:", A | B) # or A.union(B)
# Intersection
print("Intersection of A and B:", A & B) # or A.intersection(B)
# Difference
print("Difference of A and B (A - B):", A - B) # or A.difference(B)
print("Difference of B and A (B - A):", B - A)
# Symmetric Difference
print("Symmetric Difference of A and B:", A ^ B) # or A.symmetric_difference(B))
# Subset and Superset
print("\nIs A subset of B?", A.issubset(B))
print("Is A superset of B?", A.issuperset(B))
Student name- Sachin Page no-3
Roll no- 48 D.O.P-26/08/2025
Course- BCA AI&DS
OUTPUT-
Set A: {1, 2, 3, 4, 5}
Set B: {4, 5, 6, 7, 8}
Union of A and B: {1, 2, 3, 4, 5, 6, 7, 8}
Intersection of A and B: {4, 5}
Difference of A and B (A - B): {1, 2, 3}
Difference of B and A (B - A): {8, 6, 7}
Symmetric Difference of A and B: {1, 2, 3, 6, 7, 8}
Is A subset of B? False
Is A superset of B? False