True inconsistency in Python
Ben Finney
bignose-hates-spam at and-benfinney-does-too.id.au
Thu Nov 13 01:18:13 EST 2003
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.
--
\ "Injustice is relatively easy to bear; what stings is justice." |
`\ -- Henry L. Mencken |
_o__) |
Ben Finney <http://bignose.squidly.org/>
More information about the Python-list
mailing list