Numeric don't compare arrays correctly

Alexander Schmolck a.schmolck at gmx.net
Fri Jun 6 18:56:52 EDT 2003


"Mike C. Fletcher" <mcfletch at rogers.com> writes:

> Alexander Schmolck wrote:
> ...
> 
> >``3 < 1 < 4`` (False in python, True in most other languages where it isn't a
> >syntax error)
> >

> OMG! That's horrific! It actually took me 3 or 4 seconds to even come up
> with a rationale for why it would be considered true when it so obviously is
> trying to say something false.

Well, it is only obvious because you (and I) are already used to a rather
hackish notation.

> Hopefully all those languages with these semantics issue a strong warning
> during compilation (1/5 ;) ) that this statement does nothing useful and
> should never be used in anything save obfuscated code contests :) .

Nope:

#include <stdio.h>

int main()
{
    printf("Is 1 < 1 < 1 true? %d\n", 1 < 1 < 1);
    return 0;
}
> gcc -Wall /tmp/ex.c
> a.out
Is the 1 < 1 < 1 true? 1


> Every once in a while I thank Guido for God's common sense (or vice versa).

I tend to agree, but in this case I'm not so sure. After all pythons
conformance with the expected "common sense" behavior breaks down nastily for
rich comparisons.

'as




More information about the Python-list mailing list