Simplify Chained Comparison Simplify Chained Comparison python python

Simplify Chained Comparison


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:

Reference: https://docs.python.org/3/reference/expressions.html#comparisons


It can be rewritten as:

start <= x <= end:

Or:

r = range(start, end + 1) # (!) if integersif x in r:    ....


matomo