DEV Community

Mišo
Mišo

Posted on

1

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)

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay