Python efficiency of and vs multiple ifs

后端 未结 5 922
太阳男子
太阳男子 2021-02-07 05:32

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         


        
5条回答
  •  粉色の甜心
    2021-02-07 06:29

    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.

提交回复
热议问题