Here’s a simple Python program to check whether an element is present in a set:
# Define a set
my_set = {10, 20, 30, 40, 50}
# Element to check
element = 30
# Check if the element is in the set
if element in my_set:
print(f"{element} is present in the set.")
else:
print(f"{element} is not present in the set.")
Explanation:
- The
in
operator is used to check if an element exists in the set. - If the element is found, it prints a confirmation message; otherwise, it states that the element is not present.