I have two integer value cnt_1
and cnt_2
, and I write the following statements:
if cnt_1 < 0 and cnt_2 >= 0:
# some code
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?
The question is a little different from link, there are different variables in comparison.
Your expression can be rewritten as:
if cnt_1 < 0 <= cnt_2:
This is called comparison chaining.
Pycharm is trying to tell you that the equation can be simplified. If you want to know what PyCharm would prefer it to be, PyCharm will help automate this fix. If you navigate your cursor to the underlined code and do:
Alt + Enter -> 'Simplify chained expression'
PyCharm will change this to:
if cnt_1 < 0 <= cnt_2:
The warning will now be gone. If you prefer the original code and are just wanting the warning to go away you can place your cursor on the warning and do
Alt + Enter -> 'Ignore...'
And this type of error will no longer be flagged. You can also access both of these options on a global scale by doing.
Code->"Inspect code..."-> (Choose the scope you'd like to inspect) -> Ok
This will give you a list of all the warnings in the scope you've selected and provide you with an automated method to fix many of them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With