I would like to know why 0.0== False
returns True
in Python. I know 0==False
returns True
because Bool
is a subclass of int
so essentially you are comparing the same data type but is the same true for float?
Asked
Active
Viewed 784 times
1

Vykta Wakandigara
- 339
- 2
- 10
-
The duplicates are not exactly the same question, but what you are trying is similar to `int(0) == float(0)`, which is also `True`. – Selcuk Feb 05 '20 at 05:46
-
print(bool(float(0.00))) comes out false which means float of 0.00 is false which is why 0.0==False returns True. – Raj Verma Feb 05 '20 at 05:50
-
@RajVerma: No, the float is not interpreted as a boolean. If it was, `2.0 == True` would be true. – user2357112 Feb 05 '20 at 05:57
-
bool(0) is False which is True and bool(0.0) is also false which is correct. Hence when you say 0.00==False or 0==False it comes True. its the condition. Checked n tested. I never said float is treated as bool. – Raj Verma Feb 05 '20 at 06:13
-
1@RajVerma: `bool(2.0)` is `True`, but `2.0 == True` is false. – user2357112 Feb 05 '20 at 06:15
-
right, but that's not the point. – Raj Verma Feb 05 '20 at 06:19
-
2@RajVerma I think your comment is a bit misleading, just because some combination of type conversions can make two values equal, doesn't mean that `==`ing them will or should resolve `True`. – Hymns For Disco Feb 05 '20 at 07:24
-
Sure, I get it! – Raj Verma Feb 05 '20 at 08:04