和vs多个ifs的Python效率 [英] Python efficiency of and vs multiple ifs
本文介绍了和vs多个ifs的Python效率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在if语句中使用和以及在多个if语句中使用,效率之间存在差异吗?换句话说,是类似
Is there an efficiency difference between using and in an if statement and using multiple if statements? In other words, is something like
if expr1 == expr2 and expr3==expr4:
dostuff()
然后从效率的角度来看:
different from an efficiency standpoint then:
if expr1 == expr2:
if expr3 == expr4:
dostuff()
我的基本测试并没有显示出差异,但是知识更多(或至少是更彻底的测试)的人有明确的答案吗?
My very basic testing does not reveal a difference, but does someone with more knowledge (or at least more thorough testing) have a definitive answer?
推荐答案
在两种情况下, expr1 == expr2
的计算结果为 false $ c $
if
中的c>,秒将不被评估。
In either case, expr1 == expr2
evaluates to false
in if
, the second will not be evaluated.
这篇关于和vs多个ifs的Python效率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文