Skip to content

Chain Compares

Documentation Index

Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt

Use this file to discover all available pages before exploring further.

Combine two compares on same value into a chained compare

if 1 < b and b < 3:
print("b is between 1 and 3")
if 1 < b < 3:
print("b is between 1 and 3")

Two compare operations on the same value can be chained together. This is described in detail in the Python comparison docs.

Chaining compares is how they are written in mathematics and makes them easier to read.