max max - 1 year ago 67
Python Question

Why doesn't the operator module have a function for logical or?

In Python 3, operator.or_ is equivalent to the bitwise

, not the logical
. Why is there no operator for the logical

Answer Source

The or and and operators can't be expressed as functions because of their short-circuiting behavior:

False and some_function()
True or some_function()

in these cases, some_function() is never called.

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download