Saturday, January 1, 2022

How to check whether an element exists in a list using For Loop in Python Program

The Python Program to search for an element in a List
# import sys
# print("Python Version: ", sys.version)

L1 = {3, 5, 'Vijay', 'James Bond', '007', 15}

search_element = input("Please enter an element to search: ")

for element in L1:

    if search_element == '%s' % (element):

        print("The element found in the list")

        break

else:

    print("The element not found in the list")



# ------------------------------------------------------------------------------------------------------------------------ #
Input: 
007

Output :
The element found in the list
# ------------------------------------------------------------------------------------------------------------------------ #


No comments:

Post a Comment

Hi User, Thank You for visiting My Blog. Please post your genuine Feedback or comments only related to this Blog Posts. Please do not post any Spam comments or Advertising kind of comments which will be Ignored.

Featured Post from this Blog

How to compare Current Snapshot Data with Previous Snapshot in Power BI

How to Dynamically compare two Snapshots Data in Power BI Scenario: Suppose, we have a sample Sales data, which is stored with Monthly Snaps...

Popular Posts from this Blog