How to Check if Element Exists in List in Python
In this tutorial, we will program 'How to Check if an Element Exists in a List in Python'. We will learn how to identify if a specific element is present in a list. The objective is to enable you to efficiently check for the existence of elements within a list. I will provide a sample program to demonstrate the actual coding of this tutorial.
This topic is very easy to understand; just follow the instructions I provide, and you can also do it yourself with ease. The program I will show you covers the basics of programming for finding a missing element in a list. I will do my best to provide you with the easiest way for checking the list. So, let's start with the coding.
Getting Started:
First you will have to download & install the Python IDLE's, here's the link for the Integrated Development And Learning Environment for Python https://www.python.org/downloads/.
Creating Main Function
This is the main function of the application. The following code will display a simple GUI in terminal console that will display program. To do this, simply copy and paste these blocks of code into the IDLE text editor.- lst=[ 1, 6, 3, 5, 3, 4 ]
- ret = False
- while True:
- print("\n================== Check if Element Exists in List ==================\n\n")
- i=int(input("Enter a number: "))
- if i in lst:
- print("The number you entered is already exist!")
- else:
- print("The number you entered is currently not exist!")
- opt = input("\nDo you want to try again?(yes/no): ")
- if opt.lower() == 'yes':
- ret=False
- elif opt.lower() == 'no':
- ret=True
- print("Exiting program....")
- else:
- print("Please enter yes/no:")
- break
- if ret == False:
- continue
This Python script checks if a user-provided number exists in a predefined list. It repeatedly prompts the user to enter a number and then checks if that number is present in the list lst. It prints a message indicating whether the number exists in the list. After each check, it asks the user if they want to try again or exit the program.
Output:

The How to Check if Element Exists in List in Python source code that I provide can be download below. Please kindly click the download button.
There you have it we successfully created How to Check if Element Exists in List in Python. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!
More Tutorials for Python Language