Search code examples
pythonintegercontains

Check if a digit is present in a list of numbers


How can I see if a number contains certain digits?

numbers = [2349523234, 12345123, 12346671, 13246457, 134123431]

for number in numbers:
    if (4 in number):
        print(number + "True")
    else:
        print("False")

Solution

  • 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'.format(number))
    

    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)