[Python-ideas] True and False are singletons

Steven D'Aprano steve at pearwood.info
Mon Mar 18 18:54:26 EDT 2019

On Tue, Mar 19, 2019 at 11:32:56AM +1300, Greg Ewing wrote:
> Tim Delaney wrote:
> >I would argue the opposite - the use of "is" shows a clear knowledge 
> >that True and False are each a singleton and the author explicitly 
> >intended to use them that way.
> I don't think you can infer that. It could equally well be someone who's
> *not* familiar with Python truth rules and really just meant "if x".
> Or someone who's unfamiliar with booleans in general and thinks that
> every "if" statement has to have a comparison in it.


Writing "if some_bool = true" in static typed languages is pretty 
common. I used to see it a lot in my Pascal days. In fairness that was 
because I used to write some of it myself :-(

For some reason it rarely seems to happen when the flag being tested is 
itself a boolean expression:

    if x > 0:  # this
    if (x > 0) is True:  # but never this

which gives credence to your idea that people expect that people are 
(consciously or unconsciously) expecting every if to include a 


More information about the Python-ideas mailing list