You can use List. Contains() method. Determines whether an element is in the List<T> .
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With