首页 > 解决方案 > 操作顺序和/或

问题描述

我对python中的操作顺序有疑问,请参见下面的代码。如果我想浓缩成一行,我有一个嵌套的。

下面的代码读取“a”、“b”和“c”是否在列表传递中,或者“c”是否也在列表传递中,而不考虑 abc。我希望代码读取列表中的“a”和“b”以及“c”或“d”是否在列表中

if "a" and "b" in list:
    if "c" or "d" in list:
        print()

if "a" and "b" in list and "c" or "d" in list:
    print()
    # keyerror "d" not in list

标签: pythonpython-2.7

解决方案


推荐阅读