No Widget Added

Please add some widget in Offcanvs Sidebar

Shopping cart

shape
shape

Python Program To Check Whether Element Present In Set Or Not Example

  • Home
  • Blog
  • Python Program To Check Whether Element Present In Set Or Not Example
Python Program To Check Whether Element Present In Set Or Not Example

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.

Leave A Comment

Your email address will not be published. Required fields are marked *