DEV Community

Mišo
Mišo

Posted on

Python chained comparisons with == and !=

IDEA (PyCharm) suggested me today to simplify one condition in Python count > 0 and count != prev_count. I was asking myself how? And it was transformed to 0 < count != prev_count.

I knew this is possible in Python but because every example out there always shows something like min < value <= max I somehow never realized this is possible too. It makes sense because according to documentation all comparison operators are supported for chained comparison. Have it in mind next time :)

Top comments (0)