0

I tried some comparisons with None. Here are the tests -

1 > None
2 > None
0 > None
-100000 > None

All comparisons returned True. Why did this happen? Why did NoneType comparisons work with intType? Will the results be True in all cases?

Is it good coding practice to use None in comparisons?


Note: the comparisons only worked in Python 2.x. Python 3.x doesn't seem to support the comparisons (tested on Python 2.7.6 and Python 3.4.0).

Confuse
  • 5,646
  • 7
  • 36
  • 58
  • 1
    Hmm...what about [this question](https://stackoverflow.com/questions/33049388)? – Remi Guan Oct 11 '15 at 06:44
  • 1
    If you wanted to, you _could_ create a custom class that compares less than `None`. But generally, the only tests involving None should be identity tests, like `if a is None:`. – PM 2Ring Oct 11 '15 at 07:24

0 Answers0