Is 0 > None??

Andy Todd andy_todd at spam.free.yahoo.com
Sun Sep 2 20:40:47 EDT 2001


Manus Hand <manushand at home.com> wrote in <3B8F4B03.EFE5E0ED at home.com>:

>It was in 1.5.1, but it wasn't in 1.5.2 or 2.0 or even (I think) 2.1.
>
>But it is again in 2.1.1.  Aauugghh!  Now I know that maybe I shouldn't
>have written code that depends on where None compares to the integer
>values, but hey, it sure made for a very handy cmp() function!
>
>Would it be possible to get a permanent decision on this one, please?
>
>If I got my vote, I would like 0 < sys.minint
>
>Version 2.1.1 has 0 > sys.maxint
>
>Thanks,
>Manus
>

For meaningful reading, I refer the casual observer to the other answers to 
this question. But, just to add my two pennorth;

I tend to treat 'None' in Python the same as 'NULL' in an RDBMS. The only 
possible value it can represent is 'I dont know'. A valuable mental trick 
passed on by a wise teacher many years ago. This is to remind yourself that 
you cannot explicitly compare anything to None because it could 
*theoretically* return any value it chooses.

When you are writing code and perform any sort of comparisons, repeat to 
yourself "None means 'I dont know'" and you will quickly find you don't do 
anything like this.

Thus to extrapolate from your posts above;

>>> if 0 > None:

should make you say to yourself 'if zero is greater than I dont know', 
leading you to exactly the correct answer - false. 

>>> if value < None:

should make you say to yourself 'if the item referenced by value is less 
than I dont know then ...'
Again leading to an answer of false.

Sitting-here-mumbling-to-myself-ly y'rs,
Andy
-- 
Content free posts a speciality



More information about the Python-list mailing list