python - 操作顺序和/或
问题描述
我对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
解决方案
推荐阅读
- python - 如何在 QTextEdit 中插入和清除占位符
- c++ - 取消来自辅助线程的请求以强制 MPI_Wait 返回
- google-bigquery - SQL UDF - 结构差异
- python - 优化大型数据集的迭代和替换
- kubernetes - Minikube 无法启动:“找不到节点‘minikube’”
- javascript - 解构嵌套参数,未定义错误
- html - 为什么占用这么多初始空间,如何控制呢?
- android - 使用 AS 同步时将运行 gradle 任务
- typescript - Observable 在 Lambda 中的处理方式是否与 Promise 不同?
- php - [Route: topic.index] [URI: topic/{id}/group] 缺少必需的参数