Is 0 > None??

Andy Todd andy_todd at spam.free.yahoo.com
Mon Sep 3 19:45:34 EDT 2001


Isaac To <kkto at csis.hku.hk> wrote in <7iofosmr7x.fsf at enark.csis.hku.hk>:

>>>>>> "Andy" == Andy Todd <andy_todd at spam.free.yahoo.com> writes:
>
>    Andy> Thus to extrapolate from your posts above;
>
>    >>>> if 0 > None:
>
>    Andy> should make you say to yourself 'if zero is greater than I
>    dont Andy> know', leading you to exactly the correct answer - false.
>
>No (this ends up with 0 < None being false as well, but is clearly
>untrue). 

The results from that comparison (on Python 2.1.1 on cygwin) are;

>>> 0 < None
0
>>> 0 > None
1

So I was indeed wrong. But my point was valid ;-) Logically, comparing any 
actual value to 'None' is wrong. As soon as you put those four characters 
in your statement you should start mumbling to yourself about 'I dont know' 
and replace '==' and '!=' with 'is' and 'is not'. It is a semantic rather 
than a syntatic thing but my point was that it helps me out.

Of course, in a lot of Python code we dont even bother with 'is', instead 
you see;

>>> if myVariable:
...     print "myVariable contains a value"

which is a short hand for the same thing.

One of the things that I absolutely hate in 'C' is looking at statements 
which perform an assignment and then evaluate the result of the operation 
to true or false depending on what the calling function returns. It 
confuses me at every turn and is one of the main reasons that Python is a 
lot more sane and readable to me.

> Comparison of anything between unrelated types are bounded to
>end up in arbitrary result.  The result is guaranteed to be consistent
>within a specific run, or even a specific platform-version pair, but can
>differ if platform or version changes.  None and Integer are of
>unrelated types, and comparison should be done only to make things like
>an untyped hash.  This is well documented, I think.

I couldn't agree more, even in a dynamically typed language you should 
always be aware of what you are comparing. The concept of 'None' is 
documented, how well is a matter of personal opinion, I was just trying to 
add another viewpoint on the subject which should ring a bell with any 
other database heads (like myself) trying to get to grips with Python.

>
>Regards,
>Isaac.

Regards,
Andy
-- 
Content free posts a speciality



More information about the Python-list mailing list