[Python-3000] Status of True, False, bool type

Josiah Carlson jcarlson at uci.edu
Tue Jan 2 07:48:26 CET 2007


"Mike Orr" <sluggoster at gmail.com> wrote:
> 
> On 1/1/07, Josiah Carlson <jcarlson at uci.edu> wrote:
> >
> > "Mike Orr" <sluggoster at gmail.com> wrote:
> > > Huh?  'True == 1' is a "feature"?  '16 + (0 == 0)' being illegal is a
> > > "Javaism"?  Would somebody care to explain this?  It's acceptable that
> > > 2 is true but not True?  Why do we need 1 for True at all if we have
> > > True?
> >
> >     >>> 1 is not True
> >     True
> >     >>> 1 == True
> >     True
> >     >>> isinstance(True, int)
> >     True
> >
> > If you are suggesting that we change this behavior, stop, it is not
> > going to happen. If you are asking why this is the case, I would imagine,
> > is based in C/C++/many other sane and insane languages' handling of
> > boolean true.
> 
> It doesn't matter to me if it stays.  I thought 1 meaning True was
> just a concession to backward compatibility because Python didn't have
> True and False from the beginning.  So this would be a good time to
> ditch it.  Having 1 mean two different things means you can't tell
> immediately whether a variable is numeric or boolean; e.g., is it a
> line count or just a statement that some lines exist?  Fortunately I
> rarely see Python code nowadays that uses 1 this way.

But 1 doesn't mean True.  1 stands for the value 1.  True happens to be,
by long familliar semantics to many users, equal to 1, just as...

    bool c = true;
    printf("%i", c);

... will print 1 in C.  Don't read more into it than necessary.  As
Terry Reedy suggested, read PEP 285, which offers better reasoning than
I have or will provide.

 - Josiah



More information about the Python-3000 mailing list