在Python中,可以使用循环或列表推导式来匹配数组中的值。
array = [1, 2, 3, 4, 5]
value = 3
for item in array:
if item == value:
print("匹配到值", value)
break
array = [1, 2, 3, 4, 5]
value = 3
matches = [item for item in array if item == value]
if len(matches) > 0:
print("匹配到值", value)
上述代码将匹配数组array
中的值是否等于给定的value
。如果匹配到值,则会打印出匹配到的值。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
相关推荐:怎么用python匹配数据