[Tutor] Question about 'Predicate Methods'

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Wed Apr 2 20:41:00 2003


On Mon, 24 Mar 2003, ahimsa wrote:

> > (In the newest versions of Python, the results of the above tests will
> > return the values 'True' and 'False', rather than 1 and 0, so expect
> > to see slightly different displays.)
>
> What version are you referring to here, and what of backwards
> compatibility if someone specifically wants the 1 or 0 return (i.e. an
> integer) rather than a string (as in 'true'/'false')?

Hi Andy,


Python 2.2.1 introduced the boolean values 'True' and 'False' as names:

    http://python.org/peps/pep-0285.html

as a gradual step toward having real boolean types in Python.  However,
the comparison operators still returns 1 or 0 in Python 2.2.1.  In Python
2.3, comparisons will return these boolean objects.

Code that uses 0 or 1 should still work:

###
>>> True == 1
1
>>> type(True)
<type 'int'>
>>> False == 0
1
###

as True and False are subclassed from the integers.


Hope this helps!