【发布时间】:2022-12-22 00:50:49
【问题描述】:
我想减少 Python 中的以下 if 循环。有什么有效的方法吗?
if a and b:
print("case1")
elif not a and b:
print("case2")
elif not a:
print("case3")
【问题讨论】:
-
这些不是 if 循环(不存在)。相反,它们是 if 语句。
标签: python python-3.x
我想减少 Python 中的以下 if 循环。有什么有效的方法吗?
if a and b:
print("case1")
elif not a and b:
print("case2")
elif not a:
print("case3")
【问题讨论】:
标签: python python-3.x
print("case1" if a and b else "case2" if not a and b else "case3")
【讨论】: