小编Kof*_*611的帖子

有没有办法缩短这个 if 语句?

我试图做到这一点,如果两个或多个变量为 False,则语句结束;但是按照我的方式,代码占用了太多空间。

if g == False and h == False:
  print("Use a different formula.")
  return
elif g == False and i == False:
  print("Use a different formula.")
  return
elif g == False and c == False:
  print("Use a different formula.")
  return
elif h == False and i == False:
  print("Use a different formula.")
  return
elif h == False and c == False:
  print("Use a different formula.")
  return
elif i == False and c == False:
  print("Use a different formula.")
  return …
Run Code Online (Sandbox Code Playgroud)

python boolean python-3.x

3
推荐指数
1
解决办法
38
查看次数

标签 统计

boolean ×1

python ×1

python-3.x ×1