How to check if a specific integer is in a list


I want to know how to make an if statement that executes a clause if a certain integer is in a list.

All the other answers I've seen ask for a specific condition like prime numbers, duplicates, etc. and I could not glean the solution to my problem from the others.


Answers:


You could simply use the in keyword. Like this :

if number_you_are_looking_for in list:
    # your code here

For instance :

myList = [1,2,3,4,5]

if 3 in myList:
    print("3 is present")