True inconsistency in Python

Ron Adam radam2 at tampabay.rr.com
Thu Nov 13 02:18:30 EST 2003


On 13 Nov 2003 17:08:13 +1050, Ben Finney
<bignose-hates-spam at and-benfinney-does-too.id.au> wrote:

>On Thu, 13 Nov 2003 06:26:09 GMT, Ron Adam wrote:
>> The only thing that surprises me in all of this is the "if var:"
>> evaluating to true for numbers other than 1.  That's new to me,  I
>> would have expected an exception in that case.
>
>Python has only recently gained a Boolean type ('bool').
>
>    <http://www.python.org/peps/pep-0285.html>
>
>Before that, Boolean logic was done with integer values.  Zero equated
>to Boolean false, non-zero equated to Boolean true; and the default
>Boolean true value was simply the integer 1.
>
>This conflation of types is confusing, and (like many other languages)
>Python has now "grown a Boolean type" to distinguish integer 0 and 1
>from Boolean False and True.  However, the previous behaviour is still
>supported -- for how long, I don't know.

That's good to know.  I've always explicitly defined my bool values as
0 and 1 so it's never been a problem. 

Thanks for the PEP link,  it was informative.  

_Ron Adam






More information about the Python-list mailing list