是否有一种方法可以找出哪种条件(在许多情况下使用或使用)在“ if”中由于它在IF内部输入,因此被评估为true吗?
我有一个if语句,假设:
if cond1 or cond2 or cond3:
do_something()
我可以找出这三个条件(cond1,cond2和cond3)是正确的,因为它进入了内部并执行do_something()?
PS:我正在寻找答案,这并不建议我使用另外2个如果在我的下方以找出正确的答案。
I have an if statement, let's say:
if cond1 or cond2 or cond3:
do_something()
Can I find out which among these three conditions (cond1,cond2 and cond3) was true because of which it entered inside and executed do_something()?
P.S: I'm looking for answers which doesn't suggest me to use another 2 if's below my if to find out which was true.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在循环中进行操作:
You could do it in a for loop: