Google News
logo
Python Program to Check if an item exists
You can check if an item exists in a set using the `in` operator. Here's an example program :
Program :
# create a set
my_set = {"apple", "banana", "cherry"}

# check if an item exists in the set
if "banana" in my_set:
    print("Yes, 'banana' exists in the set")
else:
    print("No, 'banana' does not exist in the set")

# check if an item does not exist in the set
if "orange" not in my_set:
    print("Yes, 'orange' does not exist in the set")
else:
    print("No, 'orange' exists in the set")
Output :
Yes, 'banana' exists in the set
Yes, 'orange' does not exist in the set