Program to check if a name is present in a given set of names in python
In the python programming article, we are going to learn
-
program to check if a name is present in a given set of names in python
Program to check if a name is present in a given set of names in Python
The program is as follows:
# Owner : TutorialsInhand Author : Devjeet Roy
names = {"Devjeet","Ajit","Bulbul","Shawriya"}
searchable = input("Enter the name you are searching for: ").strip()
if searchable in names:
print("This name exist in the set.")
else:
print("The name doesn's exist in the set. ")
The output of the program is as follows:
PS C:\Users\DEVJEET\Desktop\tutorialsInHand> python code.py
Enter the name you are searching for: Devjeet
This name exist in the set.
PS C:\Users\DEVJEET\Desktop\tutorialsInHand> python code.py
Enter the name you are searching for: Sus
The name doesn's exist in the set.
Few important points about the program
1. We have the "in" operator in Python which helps us to check if an item is present in a Python set, list, tuple or dictionery in python.
2. The strip() function helps us to remove leading and trailing extra spaces in the input string provided by the user.
Would you like to see your article here on tutorialsinhand.
Join
Write4Us program by tutorialsinhand.com
About the Author
Devjeet Roy
Full Stack Web Developer & Blockchain Enthusiast
Page Views :
Published Date :
Oct 13,2022