How can I see if an index contains certain numbers?
numbers = [2349523234, 12345123, 12346671, 13246457, 134123431]
for number in numbers:
if (4 in number):
print(number + "True")
else:
print("False")
Python isdigit() method returns True if all the characters in the string are digits. It returns False if no character is digit in the string.
bool containsDigit(int number, int digit); If number contains digit, then the function should return true . Otherwise, the function should return false .
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.
Use the all() function to check if all elements in a list are integers, e.g. if all(isinstance(item, int) for item in my_list): . The all() function will return True if all of the elements in the list are integers and False otherwise.
You would have to do string comparisons for this
for number in numbers:
if '4' in str(number):
print('{} True'.format(number))
else:
print("False")
It isn't really meaningful to ask if the number 4
is "in" another number (unless you have some particular definition of "in" in mind)
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