Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a specific integer is in a list

People also ask

How do you check if an integer is present in a list?

You can use List. Contains() method. Determines whether an element is in the List<T> .

How do you check if a specific number is in a list Python?

We can use the in-built python List method, count(), to check if the passed element exists in the List. If the passed element exists in the List, the count() method will show the number of times it occurs in the entire list. If it is a non-zero positive number, it means an element exists in the List.


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")

Are you looking for this?:

if n in my_list:
    ---do something---

Where n is the number you're checking. For example:

my_list = [1,2,3,4,5,6,7,8,9,0]
if 1 in my_list:
    print 'True'