Brynn McCullagh Brynn McCullagh - 1 year ago 333
Python Question

PyCharm: "Simplify Chained Comparison"

I have an integer value

, and I need to check if it is between a
values, so I write the following statements:

if x >= start and x <= end:
# do stuff

This statement gets underlined, and the tooltip tells me that I must

simplify chained comparison

As far as I can tell, that comparison is about as simple as they come. What have I missed here?

Answer Source

In Python you can "chain" comparison operations which just means they are "and"ed together. In your case, it'd be like this:

if start <= x <= end:


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download