Reputation: 333
Does python short circuit a boolean like a==b==c
, i.e., if a==b
is false, then the second equality isn't evaluated? Is the compound equality just syntactic sugar for a==b and b==c
?
Upvotes: 1
Views: 52
Reputation: 280237
Yup. From the docs:
Comparisons can be chained arbitrarily, e.g.,
x < y <= z
is equivalent tox < y
andy <= z
, except thaty
is evaluated only once (but in both casesz
is not evaluated at all whenx < y
is found to be false).
This applies to any chained comparison, regardless of the chosen comparison operators.
Upvotes: 5
Reputation: 366
From the Python docs:
Comparisons can be chained arbitrarily; for example,
x < y <= z
is equivalent tox < y and y <= z
, except that y is evaluated only once (but in both cases z is not evaluated at all whenx < y
is found to be false).
Upvotes: 3