[Tutor] Question about 'Predicate Methods'
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')?
Python 2.2.1 introduced the boolean values 'True' and 'False' as names:
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
>>> False == 0
as True and False are subclassed from the integers.
Hope this helps!