True/False value testing

Marko Rauhamaa marko at pacujo.net
Thu Jan 7 07:07:26 EST 2016


Chris Angelico <rosuav at gmail.com>:

>> Stirring the pot:
>>
>>    >>> (2 < 3) is True
>>    True
>>
>> but is that guaranteed?
>
> Yes. When you do comparisons involving integers, the result is an
> actual boolean value - not just a truthy value, but the exact value
> True or False.

I couldn't locate that bold statement in the language spec (see <URL:
https://docs.python.org/3/library/stdtypes.html#comparisons>).

However, I *could* find this statement:

   1. [or] is a short-circuit operator, so it only evaluates the second
      argument if the first one is False.

   2. [and] is a short-circuit operator, so it only evaluates the second
      argument if the first one is True.

   <URL: https://docs.python.org/3/library/stdtypes.html#boolean-op
   erations-and-or-not>

The wording is very unfortunate (both the use of the word "is" and the
explicit references to the builtin constants False and True).


Marko



More information about the Python-list mailing list