bool behavior in Python 3000?
steve at REMOVE.THIS.cybersource.com.au
Wed Jul 11 01:24:11 CEST 2007
On Tue, 10 Jul 2007 13:13:38 -0600, Steven Bethard wrote:
> It's much easier to explain to newcomers that *, + and - work on True
> and False as if they were 1 and 0 than it is to introduce them to a two
> element boolean algebra. So making this kind of change needs a pretty
> strong motivation from real-world code.
Pretending that False and True are just "magic names" for 0 and 1 might be
"easier" than real boolean algebra, but that puts the cart before the
horse. Functionality comes first: Python has lists and dicts and sets
despite them not being ints, and somehow newcomers cope. I'm sure they
will cope with False and True not being integers either.
I mean, really, does anyone *expect* True+True to give 2, or that 2**True
even works, without having learnt that Python bools are ints? I doubt it.
And the old Python idiom for an if...then...else expression:
["something", "or other"][True]
tends to come as a great surprise to most newbies. So I would argue that
bools being ints is more surprising than the opposite would be.
More information about the Python-list