chained comparison
Writing several comparisons in a row, as in 0 <= x < 10, which means 0 <= x and x < 10.
In more detail
Each middle value is evaluated once. It is clearer than joining the two tests with and, but x == 1 or 2 is not a chain: it is always true, because 2 on its own is truthy.
Related terms
- comparison operator — An operator that compares two values and gives true or false, such as equal, not equal, less than or greater than.
- logical operator — An operator such as AND, OR or NOT that combines or reverses true-or-false conditions.
Taught in
- Compound Boolean Expressions — Hands-on Python: Complete Video Course & Book
- Branching With If, Elif And Else — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Conditions The Exam Loves — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep