Closed Danack closed 2 years ago
notes on it: https://mathspp.com/blog/pydonts/chaining-comparison-operators
Did you know that you can actually chain an arbitrary number of comparison operators? For example, a == b == c == d == e checks if all five variables are the same, while a < b < c < d < e checks if you have a strictly increasing sequence.
Good uses at 4 minute mark: https://www.youtube.com/watch?v=M3GAJ1AIIlA&ab_channel=mCoding
RFC name
Python allows this:
if (0 <= x <= 10) {...}
Summary
It's nice as it reads nice, but also avoids a problem. That code is equivalent to:
But imagine we had:
and foo() had side-effects then the equivalent code:
is calling foo() twice. The workaround of:
is even jankier.