This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Unexpected feature vs. integer and True values
Type: Stage:
Components: Interpreter Core Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: bacademy, georg.brandl
Priority: normal Keywords:

Created on 2007-04-06 15:28 by bacademy, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg31712 - (view) Author: dev@bacademy (bacademy) Date: 2007-04-06 15:28
Integer 1 interpreted as True.
I didn't expect the following:

Python 2.5 (r25:51908, Apr  4 2007, 10:19:35)
[GCC 4.1.1 20060724 (prerelease) (4.1.1-3mdk)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>> v = 2
>>> 0.0 if v == True else float(v)
2.0
>>> v = 1
>>> 0.0 if v == True else float(v)
0.0

I know how to fix this, by writing

0.0 if v is True else float(v)

but to casual observer it is not obvious...




msg31713 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-04-06 18:01
It may be, but it is not a bug (bool inherits from int) and documented (I think...).
msg31714 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-04-06 20:56
It may be, but it is not a bug (bool inherits from int) and documented (I think...).
History
Date User Action Args
2022-04-11 14:56:23adminsetgithub: 44810
2007-04-06 15:28:00bacademycreate