[Python-ideas] Changing the meaning of bool.__invert__

Pavol Lisy pavol.lisy at gmail.com
Sun Apr 17 14:24:21 EDT 2016

2016-04-09 17:43 GMT+02:00, Steven D'Aprano <steve at pearwood.info>:
> On Fri, Apr 08, 2016 at 02:52:45PM +0900, Stephen J. Turnbull wrote:
>> I just don't see why the current
>> behaviors of &|^ are particularly useful, since you'll have to guard
>> all bitwise expressions against non-bool truthies and falsies.
> flag ^ flag is useful since we don't have a boolean-xor operator and
> bitwise-xor does the right thing for bools. And I suppose some people
> might prefer & and | over boolean-and and boolean-or because they're
> shorter and require less typing. I don't think that's a particularly
> good reason for using them, and as you say, you do have to guard
> against non-bools slipping, but Consenting Adults applies.

They are also useful if you need to avoid short-circuit evaluation.

More information about the Python-ideas mailing list