Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simplify Python chained comparison [duplicate]

Tags:

python

I am writing some python code in PyCharm. It is giving me a warning when I write the following test.

            return factor >= 1.0 and factor <= 2.0

Information on the warning says it is showing because the comparison can be simplified. Is there a better way of writing this comparison. An image showing the warning

like image 524
Charitoo Avatar asked Jul 12 '26 11:07

Charitoo


1 Answers

return 1 <= factor <= 2

This will eliminate that, as it's combining the two comparisons.

like image 100
Jake Conway Avatar answered Jul 15 '26 02:07

Jake Conway



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!