0

Are integers and floats other than 0 and 1 considered True or False in python?

>>> 1.1 == True
False
>>> if 1.1:
...     print("Done!")
... 
Done!

The first statement's result is False, implying that 1.1 is False, but then if 1.1 results into True. Now if I check whether 1.1 == False, this too results into False. Am I missing something obvious?

Peaceful
  • 4,920
  • 15
  • 54
  • 79
  • And [Is False == 0 and True == 1 an implementation detail or is it guaranteed by the language?](https://stackoverflow.com/questions/2764017/is-false-0-and-true-1-an-implementation-detail-or-is-it-guaranteed-by-the) – Tomerikoo Feb 07 '21 at 18:51
  • In short: `False == 0` and `True == 1`. Doing `if x` is not equivalent to `if x == True` rather to `if bool(x) == True`. `bool(x)` for every number different than zero is `True` – Tomerikoo Feb 07 '21 at 18:53
  • @Tomerikoo : It does I think. Thanks. But this is completely new to me! – Peaceful Feb 07 '21 at 18:53
  • 1
    Mark as duplicate, and happy reading ;) – Tomerikoo Feb 07 '21 at 18:54

0 Answers0