Is this valid ?
steve at REMOVE-THIS-cybersource.com.au
Fri Mar 21 00:06:54 CET 2008
On Thu, 20 Mar 2008 15:09:08 +0100, Rolf van de Krol wrote:
> John Machin wrote:
>> Of course. You can chain comparisons as much as you like and is
>> (semi-)sensible, e.g.
> Hmm, 'of course' is not the correct word for it.
Not at all. The Original Poster tried something, and it worked. There
were two alternatives:
(1) Writing a == b == 2 is valid.
(2) In the sixteen years that Python has been publicly available, with
tens of thousands or more developers using it, nobody had noticed that
Python had a bug in the compiler which incorrectly allowed a == b == 2
until Stef Mientki came along and discovered it.
Given those two alternatives, (2) would be very surprising indeed, and so
I think "of course" is well justified.
That Python allows chaining comparisons this way isn't really surprising.
That's a very natural thing to do. What's surprising is that other
languages *don't* allow chaining comparisons, but force you to write the
inefficient and (sometimes) confusing "(a == 2) and (b == 2)" instead.
More information about the Python-list