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

Pavol Lisy pavol.lisy at gmail.com
Fri Apr 8 17:55:34 EDT 2016


2016-04-08 17:00 GMT+02:00, Guido van Rossum <guido at python.org>:
> On Thu, Apr 7, 2016 at 6:40 PM, Steven D'Aprano <steve at pearwood.info>
> wrote:
>
>> You missed two: >> and <<. What are we to do with (True << 1)?
> [...]
>
> Those are indeed ambiguous -- they are defined as multiplication or
> floor division with a power of two, e.g. x<<n is x*2**n and x>>n is
> x//2**n (for integral x and nonnegative n). The point of this thread
> seems to be to see whether some operations can be made more useful by
> staying in the bool domain -- I don't think making both of these
> return 0 if n != 0, so let's keep them unchanged.

It is also compatible with numpy:

  np.bool_(True) <<2
  4

but there is also minus operator:

  -np.bool_(True)
  False

  -np.bool_(False)
  True


More information about the Python-ideas mailing list