Newcomer struggling with tutorial

Tim Peters tim.one at comcast.net
Sat Oct 4 23:50:37 EDT 2003


[CPK Smithies]
> Just joined this group, fascinated by Python. Many thanks to those
> who have worked so hard on it!
>
> One big problem, though: I was completely thrown by this, which I
> quote from the Tutorial:
>
>> Comparisons can be chained. For example, a < b == c tests whether a
>> is less than b and moreover b equals c.
>
> I threw a mental wobbly and wasted two hours over this:

It helps a lot if you don't type things in from memory.  Paste an actual
interactive session instead.

> a = -1
> b = 77
> c =  1
>
> (a < b)
>  True
>
> True == c
>  True
>
> (a < b) == c
>  False

That's hard to believe.  Here's a paste from an actual interactive session:

Python 2.3.2 (#49, Oct  2 2003, 20:02:00) [MSC v.1200 32 bit (Intel)] on
win32
...
>>> a = -1
>>> b = 77
>>> c = 1
>>> (a < b)
True
>>> True == c
True
>>> (a < b) == c
True
>>>

> Unfortunately I was brought up with the belief that if A == B and B
> == C, then A should == C.

Sure.  It's usually true in Python, although the realities of finite
floating-point arithmetic can violate it.

Perhaps you really typed this instead:

>>> a < b == c
False
>>>

That's also correct, because of the manual quote you gave at the top of the
message (b == c is False, so a < b == c is also False; note that

    a < b == c

is not the same thing as

   (a < b) == c

Perhaps that's confusing you.).

> I confess that after two hours worrying about this I have given up on
> Python and uninstalled it. A shame: it looked so good!

That's your choice, of course.






More information about the Python-list mailing list