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?
This isn’t enough of a performance difference, if any, to affect your decision. IMO, the decision here should be made purely from a readability perspective. The first is generally more standard, I think, but there are situations when the second might be clearer. Choose the method that best gets your intent across.