Newcomer struggling with tutorial
tjreedy at udel.edu
Sun Oct 5 06:39:50 CEST 2003
"CPK Smithies" <cpks at NOSPAM.btopenworld.com> wrote in message
news:blo2gb$ng0$1 at hercules.btinternet.com...
> from the Tutorial:
> > Comparisons can be chained. For example, a < b == c tests whether
> > less than b and moreover b equals c.
This means that a < b == c is equivalent to
(a < b) and (b == c) and not
(a < b) == c., which is something else.
Chained operators are *not* 'associative' -- you cannot insert parens
unless you so for each overlapping pair of args and insert 'and'
> I threw a mental wobbly and wasted two hours over this:
> a = -1
> b = 77
> c = 1
> (a < b)
> True == c
For a < b == c, the second test Python makes is b==c (False).
But this matches for your next test.
> (a < b) == c
For 2.2.1 (which does not have True/False on Windows .
>>> a,b,c = -1, 77, 1
>>> a < b
>>> (a < b) == 1
What version/machine were you running? Please cut and paste actual
output. If you have really discovered a bug in current Python, we
would want to know and fix it.
> Unfortunately I was brought up with the belief that if A == B and B
> then A should == C.
Why 'unfortunately'? For builtin objects, this is true in Python.
> I confess that after two hours worrying about this I have given up
> Python and uninstalled it. A shame: it looked so good!
If you really did that, it was a real shame.
Terry J. Reedy
More information about the Python-list