检查数字列表中是否存在数字 [英] Check if a digit is present in a list of numbers
本文介绍了检查数字列表中是否存在数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何查看索引中是否包含某些数字?
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")
推荐答案
您必须对以下内容进行字符串比较此
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")
问数字 4
是否在另一个数字中并没有什么意义(除非您对 in有一些特殊的定义) )
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)
这篇关于检查数字列表中是否存在数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文