为什么操作员模块不具有逻辑或功能? [英] Why doesn't the operator module have a function for logical or?

查看:45
本文介绍了为什么操作员模块不具有逻辑或功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Python 3中,operator.or_等效于按位 | ,而不是逻辑或.为什么没有逻辑或的运算符?

In Python 3, operator.or_ is equivalent to the bitwise |, not the logical or. Why is there no operator for the logical or?

推荐答案

由于短路行为:

False and some_function()
True or some_function()

在这种情况下,永远不会调用 some_function().

in these cases, some_function() is never called.

另一方面,假设的 or_(True,some_function())必须调用 some_function(),因为函数参数总是在函数之前求值被称为.

A hypothetical or_(True, some_function()), on the other hand, would have to call some_function(), because function arguments are always evaluated before the function is called.

这篇关于为什么操作员模块不具有逻辑或功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆