bool behavior in Python 3000?
Bruno Desthuilliers
bruno.42.desthuilliers at wtf.websiteburo.oops.com
Wed Jul 11 10:42:39 EDT 2007
Steven D'Aprano a écrit :
(snip)
> I mean, really, does anyone *expect* True+True to give 2, or that 2**True
> even works,
I may be biased since I learned C before Python and learned Python
before it had a Boolean type, but I'd think that having False==0 and
True==1 is not that surprising for most programmers.
> 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.
This idiom should slowly disappear now we have a clean syntax for such
expressions.
> So I would argue that
> bools being ints is more surprising than the opposite would be.
I suppose this mostly have to do with one's background.
More information about the Python-list
mailing list