"0 in [True,False]" returns True
Steve Holden
steve at holdenweb.com
Tue Dec 13 04:46:30 EST 2005
Paul Rubin wrote:
> Steve Holden <steve at holdenweb.com> writes:
>
>>The really interesting question your post raises, though, is "Why do
>>you feel it's necessary to test to see whether a variable is a
>>Boolean?".
>
>
> What's the point of having Booleans, if you can't tell them from integers?
Booleans are specifically defined as a subtype of int at the C level.
One might also ask "what's the point of having floats if you can't tell
them from integers":
>>> 0.0 in [1,2,0,4]
True
>>>
It just so happens that __contains__() uses an equality test (which it
should) and equality tests perform certain coercions (which they
arguably shouldn't, but in that case I wouldn't be the one doing the
arguing).
"""
The only thing that changes is the preferred values to represent
truth values when returned or assigned explicitly. Previously,
these preferred truth values were 0 and 1; the PEP changes the
preferred values to False and True, and changes built-in
operations to return these preferred values.
"""
PEP 285.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/
More information about the Python-list
mailing list