True == 1 weirdness

Sven R. Kunze srkunze at
Wed Sep 16 19:57:27 CEST 2015

On 16.09.2015 19:36, Random832 wrote:
> I just had another thought on *why* the other cases make me so uneasy.
> The reason this is reasonable for simple cases like a > b > c or a < b
> <= c is that, in their normal meanings, these operations are transitive.
> a > b and b > c implies a > c. a < b and b <= c implies a < c. This is
> also a good reason for allowing "==" or "is" anywhere - because it's a
> natural way to write a graph including an equivalence class: a < b == c
> < d implies b < d, a < c, and a < d. So it's a natural way of writing
> it. On the other hand, a in b in c doesn't imply a in c for several
> common cases, and a > b < c doesn't imply anything about the
> relationship between a and c, so it really shouldn't be a single
> expression.
> A chained comparison doesn't *actually* compare non-adjacent elements,
> but with well-defined transitive relationships (or... semi-transitive?
> is there a word for this? My point being that when you include some ==
> or mix <= and < together, it still allows you to make some statements
> about their relationships), you are essentially saying "a, b, c are
> ordered". The generalization to mixing arbitrary operators loses this
> aspect.

Well said!

More information about the Python-list mailing list