Can transitively related expressions (like a < b and b < c) be shortened?


If we have a transitive relation of expressions combined with and, like (a < b) and (b < c) and (c < d), can this be shortened?


Yes, this can be done by chaining the expressions with a transitive relation. Because of the order of operations, each and operator has the same precedence which means that they will just evaluate from left to right as they appear in the entire expression.


a = 1
b = 2
c = 3
d = 4

# Original expression
(a < b) and (b < c) and (c < d) # True

# Using chaining, we can shorten this.
# This will evaluate to the same result as above
a < b < c < d # True

5 posts were split to a new topic: What is the order of operations for logical operators?