如何在Python3中搜索两个项目的列表

如何在Python3中搜索两个项目的列表,python,python-3.x,list,Python,Python 3.x,List,我需要一些帮助来搜索两个不同数据段的单个列表,如何才能做到这一点,以便在这两个数据段都输出时找到值。您可以在运算符中使用两个: def both_in_list(lst, a, b): return a in lst and b in lst 您可以在操作符中使用两个: def both_in_list(lst, a, b): return a in lst and b in lst 在操作符中使用了一对 list = [2,4,8,14,16] if 2 i

我需要一些帮助来搜索两个不同数据段的单个列表,如何才能做到这一点,以便在这两个数据段都输出时找到值。

您可以在运算符中使用两个

def both_in_list(lst, a, b):
    return a in lst and b in lst

您可以在
操作符中使用两个

def both_in_list(lst, a, b):
    return a in lst and b in lst

操作符中使用了一对

    list = [2,4,8,14,16]
    if 2 in list and 4 in list
        print("2 and 4 are found in this list.")
    else:
        print("These numbers are not found in this list.")

操作符中使用了一对

    list = [2,4,8,14,16]
    if 2 in list and 4 in list
        print("2 and 4 are found in this list.")
    else:
        print("These numbers are not found in this list.")

可能重复的可能重复使用布尔值
,而不是按位
。使用布尔值
,而不是按位