在.NET VB和C中,我们可以使用AndAlso(&;)、OrElse(| |)进行逻辑操作
在Python中,等价的逻辑运算符是什么?它们是否仅限于“和”和“或”?在
更新:以下是And/Or和AndAlso/OrElse之间的差异
引自https://stackoverflow.com/a/8409488/719998
Or/And will always evaluate both1 the expressions and then return a result. They are not short-circuiting evaulation.
OrElse/AndAlso are short-circuiting. The right expression is only evaluated if the outcome cannot be determined from the evaluation of the left expression alone. (That means: OrElse will only evaluate the right expression if the left expression is false, and AndAlso will only evaluate the right expression if the left expression is true.)
在python中,可以使用逻辑门。在
例如,您可以使用
and
或&
。在https://docs.python.org/2/library/stdtypes.html#bitwise-operations-on-integer-types
Python已经这样做了:
退货:
^{pr2}$在Python中不需要AndAlso或OrElse,它延迟地计算布尔条件(docs)。在
相关问题 更多 >
编程相关推荐